Created
February 10, 2017 10:33
-
-
Save carlesba/8a7bbd4261dbf807add291a5cfb5e475 to your computer and use it in GitHub Desktop.
Chaining add function
This file contains 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
/* | |
Returns a valuable function: | |
x = add(2)(4) // x === 6 | |
y = x(1)(2) // x === 6 && y === 9 | |
z = y(10) // z === 19 | |
*/ | |
function add (n) { | |
var fn = function (m) { | |
return add(n+m); | |
} | |
fn.valueOf = function () { | |
return n | |
} | |
return fn | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment