Skip to content

Instantly share code, notes, and snippets.

@jktravis
Last active January 9, 2018 20:51
Show Gist options
  • Save jktravis/c285e507b9712eaffdcca0d9a85544ea to your computer and use it in GitHub Desktop.
Save jktravis/c285e507b9712eaffdcca0d9a85544ea to your computer and use it in GitHub Desktop.
const partial1 = function partial(fn) {
// Drop the function from the arguments list and
// fix arguments in the closure.
const args = [].slice.call(arguments, 1);
// Return a new function with fixed arguments.
return function() {
// Combine fixed arguments with new arguments
// and call fn with them.
const combinedArgs = args.concat(
[].slice.call(arguments));
return fn.apply(this, combinedArgs);
};
};
const partial2 = function partial(fn, ...args1) {
return function(...args2) {
return fn(...args1, ...args2);
};
};
const partial3 = function partial(fn, ...args) {
return fn.bind(null, ...args);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment