Created
February 6, 2019 11:51
-
-
Save skounis/5407e3954b4d7c9b1761b4fec73a9e2b to your computer and use it in GitHub Desktop.
A dead simple Closure example in Javascript
This file contains hidden or 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 partialApply = (fn, ...fixedArgs) => { | |
return function (...remainingArgs) { | |
return fn.apply(this, fixedArgs.concat(remainingArgs)); | |
}; | |
} | |
const add = (a, b) => a + b; | |
const add10 = partialApply(add, 10); |
This file contains hidden or 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
add10(5) // 15 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment