Skip to content

Instantly share code, notes, and snippets.

@webdevwilson
Created January 21, 2011 20:26
Show Gist options
  • Save webdevwilson/790351 to your computer and use it in GitHub Desktop.
Save webdevwilson/790351 to your computer and use it in GitHub Desktop.
Add curry method to functions
Function.prototype.curry = function(scope) {
scope = scope || window;
var cargs = [];
for (var i=1, len = arguments.length; i < len; ++i) {
cargs.push(arguments[i]);
}
var m = this;
return function() {
var args = [];
for (var i=0, len = cargs.length; i < len; ++i) {
args.push(cargs[i]);
}
for (i=0, len = arguments.length; i < len; ++i) {
args.push(arguments[i]);
}
return m.apply(scope, args);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment