Last active
December 30, 2015 08:59
-
-
Save PaulGiletich/7806360 to your computer and use it in GitHub Desktop.
curry is a function that returns function with first arguments pre-assigned to it. Arguments stored in closure
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
Function.prototype.curry = function () { | |
if (arguments.length<1) { | |
return this; | |
} | |
var _this = this; | |
var _args = Array.prototype.slice.call(arguments); | |
return function() { | |
return _this.apply(this, _args.concat(Array.prototype.slice.call(arguments))); | |
} | |
} | |
//example usage | |
var add = function(a,b) { | |
return a+b; | |
} | |
var add10 = add.curry(10) | |
add10(3) // 13 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment