Skip to content

Instantly share code, notes, and snippets.

@Dobby89
Last active July 5, 2018 12:21
Show Gist options
  • Save Dobby89/520dacfd8da5f00974cbd6a1b1e22aa3 to your computer and use it in GitHub Desktop.
Save Dobby89/520dacfd8da5f00974cbd6a1b1e22aa3 to your computer and use it in GitHub Desktop.
Apply an initial set of params to a method. Similar to bind() but without having to pass `this`
/**
* partiallyApply
*
* Apply an initial set of params to a method.
* Similar to bind() but without having to pass `this`
*
* @param {function} fn
* @param {*} initialArgs
*/
function partiallyApply(fn, ...initialArgs) {
return function partiallyApplied(...laterArgs) {
return fn(...initialArgs, ...laterArgs);
};
}
/**
* Usage example
*/
function person(name, age, occupation) {
///...
}
const joe = partiallyApply(person, 'Joe');
joe(30);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment