Created
May 22, 2013 09:24
-
-
Save natos/5626328 to your computer and use it in GitHub Desktop.
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 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