Created
November 4, 2009 09:42
-
-
Save fearphage/225918 to your computer and use it in GitHub Desktop.
original from http://ejohn.org/blog/partial-functions-in-javascript/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function.prototype.partial = (function(slice, undefined) { | |
return function() { | |
var fn = this, args = slice.call(arguments); | |
return function() { | |
var arg = 0, index, length = arguments.length; | |
while (((index = args.indexOf(undefined)) > -1) && (index < length)) { | |
args.splice(index, 1, arguments[arg++]); | |
} | |
return fn.apply(this, args); | |
}; | |
}; | |
})(Array.prototype.slice); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment