Skip to content

Instantly share code, notes, and snippets.

@PaulGiletich
Last active December 30, 2015 08:59
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 PaulGiletich/7806360 to your computer and use it in GitHub Desktop.
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
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