-
Notifications
You must be signed in to change notification settings - Fork 0
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
JavaScript ES6函数式编程入门经典【摘记】 #35
Comments
命令式编程和声明式编程需求:打印数组的内容
声明式编程:忽略其他,只关注做什么
声明式编程依赖forEach这些函数 |
纯函数的优点1. 可测试2. 可缓存,一个参数对应确定结果,所以结果可缓存3. 可并发,并发主要对全局变量难处理,纯函数不修改全局变量4. 可组合,functional composition5. 纯函数就是数学函数 |
高阶函数高阶函数就是接受参数为函数且返回值也为函数的函数
|
抽象的理解: 屏蔽一些东西,对外提供入口参数和返回值
|
闭包闭包:内部函数,也就是函数中的函数,上下文有三层变量,全局\外层函数\内层函数变量
|
tab unary once memoized函数
|
Array的函数实现
|
/**
es5Fun(1, 2, 3, 4, 5, "6"); |
偏应用
|
const partial = (fn, ...partialArgs) => {
let args = partialArgs;
return function(...fullArgs) {
let arg = 0;
for (let i = 0; i < args.length && arg < fullArgs.length; i++) {
if (args[i] === undefined) {
args[i] = fullArgs[arg++];
}
return fn.apply(null, args);
}
};
};
const partial = (fn, ...partialArgs) => {
let args = partialArgs;
return (...fullArgs) => {
let arg = 0;
for (let i = 0; i < args.length && arg < fullArgs.length; i++) {
if (args[i] === undefined) {
args[i] = fullArgs[arg++];
}
return fn(...args);
}
};
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
随书代码
函数的第一条原则要小,函数的第二条原则是要更小
函数和方法的区别
我的看法:函数可以作为一个变量存在,而方法只能依赖于对象,许多语言没有函数的支持,如java。而js,C,C++里函数都可以作为变量存在。
书中看法:函数是一段可以通过其名称被调用的代码,方法是必须通过其名称和其关联对象名称被调用的代码。
The text was updated successfully, but these errors were encountered: