Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[函数式编程]小记(1).纯函数 #18

Open
songhlc opened this issue Sep 7, 2016 · 0 comments
Open

[函数式编程]小记(1).纯函数 #18

songhlc opened this issue Sep 7, 2016 · 0 comments

Comments

@songhlc
Copy link
Owner

songhlc commented Sep 7, 2016

《js函数式编程》
书在这,先拿去自己看。
书里面提到 了一些简要的概念,乘热打铁。
1.纯函数。
所为纯函数就是同样的输入永远产生同样的输出,不会受到任何输入值的影响,这样的函数就是纯函数。纯函数的好处,当然就是上下文简单,可测试,可预测。
举个例子

function add(a,b){
   return a+b
}

再来看一个不纯的函数

var count = 0
function addwithCount(a,b){
     count++
     return a + b + count
}

很明显第一次调用addwithCount(0,1)和第二次调用addWithCount(0,1)明显产生的结果是不一样的。

这里不纯的函数就会产生副作用,至于具体的副作用那就看代码有多不纯了。
哦啦 一次学的东西不要太多,我们后续会慢慢展开讨论。
当然 第一次看这书的时候我对于书里的习题是一列懵逼不会写的。所以还是要多实践。
下一节见

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant