Created
February 21, 2012 14:22
-
-
Save armoucar/1876768 to your computer and use it in GitHub Desktop.
js currying
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
/*** | |
currying | |
***/ | |
function add(x, y) { | |
var oldx = x, oldy = y; | |
if (typeof oldy === "undefined") { // partial | |
return function (newy) { | |
return oldx + newy; | |
} | |
} | |
return x + y; | |
} | |
typeof add(5); // "function" | |
add(3)(4); // 7 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment