Created
March 12, 2019 11:27
-
-
Save kiinlam/5a4406c72710d859f2c77f6c64fedc31 to your computer and use it in GitHub Desktop.
es6柯里化
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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