Last active
January 9, 2018 20:51
-
-
Save jktravis/c285e507b9712eaffdcca0d9a85544ea to your computer and use it in GitHub Desktop.
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
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