Created
November 28, 2021 05:38
-
-
Save vv13/e1a18dd7e77875a62cba8619fc154a25 to your computer and use it in GitHub Desktop.
JavaScript 函数柯里化
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
function curry(fn) { | |
return function curried(...args) { | |
if (fn.length === args.length) { | |
return fn.apply(this, args); | |
} | |
return (...extraArgs) => { | |
return curried.apply(this, args.concat(extraArgs)); | |
}; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Assume we have a function, receiving several parameter and do something:
Then we should implement a fn to make function Curry: