Skip to content

Instantly share code, notes, and snippets.

@huang-x-h
Last active August 29, 2015 14:07
Show Gist options
  • Save huang-x-h/e59a6c3a175afe96b54f to your computer and use it in GitHub Desktop.
Save huang-x-h/e59a6c3a175afe96b54f to your computer and use it in GitHub Desktop.
函数柯里化
// 摘自Secrets of the JavaScript Ninja
Function.prototype.partial = function() {
var fn = this, args = Array.prototype.slice.call(arguments);
return function() {
var arg = 0;
for (var i = 0; i < args.length && arg < arguments.length; i++) {
if (args[i] === undefined) {
args[i] = arguments[arg++];
}
}
return fn.apply(this, args);
};
};
var delay = setTimeout.partial(undefined, 10);
delay(function(){
assert(true,
"A call to this function will be delayed 10 ms.");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment