Skip to content

Instantly share code, notes, and snippets.

@robmcalister
Created November 11, 2013 16:46
Show Gist options
  • Save robmcalister/7416282 to your computer and use it in GitHub Desktop.
Save robmcalister/7416282 to your computer and use it in GitHub Desktop.
Partial function binding in javascript (SOTJSN)
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);
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment