Skip to content

Instantly share code, notes, and snippets.

@natos
Created May 22, 2013 09:24
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 natos/5626328 to your computer and use it in GitHub Desktop.
Save natos/5626328 to your computer and use it in GitHub Desktop.
// currying example
function add(n) {
// save results
var r = 0;
// the real deal
function _add(n) {
r += n;
document.getElementById('r').innerHTML = r;
// return add interface
return _add;
}
// add the first n
// and return the interface
return _add(n);
}
add(5)(6)(7)(8); // 5 + 6 + 7 + 8 = 26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment