Skip to content

Instantly share code, notes, and snippets.

@carlesba
Created February 10, 2017 10:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlesba/8a7bbd4261dbf807add291a5cfb5e475 to your computer and use it in GitHub Desktop.
Save carlesba/8a7bbd4261dbf807add291a5cfb5e475 to your computer and use it in GitHub Desktop.
Chaining add function
/*
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