Created
October 7, 2012 21:18
-
-
Save fabiancarlos/3849635 to your computer and use it in GitHub Desktop.
Currying Examples
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
function Schonfinkelize(fn){ | |
var slice = Array.prototype.slice; | |
var stored_args = slice.call(arguments, 1); | |
return function (){ | |
var new_args = slice.call(arguments); | |
var args = stored_args.concat(new_args); | |
return fn.apply(null, args); | |
}; | |
} | |
function add(){ | |
return x + y; | |
} | |
var newadd = Schonfinkelize(add, 5); | |
newadd(4); // 9 | |
Schonfinkelize(add, 6)(7); // 13 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment