Skip to content

Instantly share code, notes, and snippets.

@yuyang041060120
Created August 2, 2016 06:14
Show Gist options
  • Save yuyang041060120/9f75ed8bbe12ac9d55f6c391692e7925 to your computer and use it in GitHub Desktop.
Save yuyang041060120/9f75ed8bbe12ac9d55f6c391692e7925 to your computer and use it in GitHub Desktop.
function curry(fn) {
var len = fn.length;
var ctx = this;
return innerExec([]);
function innerExec(args) {
return function () {
var newArgs = args.concat(Array.prototype.slice.apply(arguments));
if (len === newArgs.length) {
return fn.apply(ctx, newArgs);
} else {
return innerExec(newArgs);
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment