Skip to content

Instantly share code, notes, and snippets.

@bhongy
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bhongy/70b232e5b6eb12453d77 to your computer and use it in GitHub Desktop.
Save bhongy/70b232e5b6eb12453d77 to your computer and use it in GitHub Desktop.
JS: Partial Function Application
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