Last active
August 29, 2015 14:03
-
-
Save bhongy/70b232e5b6eb12453d77 to your computer and use it in GitHub Desktop.
JS: Partial Function Application
This file contains hidden or 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 partial(func /*, 0..n args */) { | |
var args = Array.prototype.slice.call(arguments, 1); // save all additional arguments to args (except index 0: func) | |
return function() { | |
var allArguments = args.concat(Array.prototype.slice.call(arguments)); // then add arguments from the original function declaration | |
return func.apply(this, allArguments); | |
}; | |
} | |
// See: http://stackoverflow.com/questions/373157/how-can-i-pass-a-reference-to-a-function-with-parameters |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment