Skip to content

Instantly share code, notes, and snippets.

@kiinlam
Created March 12, 2019 11:27
Show Gist options
  • Save kiinlam/5a4406c72710d859f2c77f6c64fedc31 to your computer and use it in GitHub Desktop.
Save kiinlam/5a4406c72710d859f2c77f6c64fedc31 to your computer and use it in GitHub Desktop.
es6柯里化
//es5
function add(a, b) {
return a + b;
}
var curriedAdd = _.curry(add);
var add2 = curriedAdd(2);
add2(1);// 3
//es6
function add(a, b) {
return a * b;
}
// var curry = f => a => b => f(a,b)
// 或者
function curry(f) {
return a=>b=>f(a,b)
}
//test
curry(add)(3)(2) //6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment