Last active
August 16, 2016 12:06
-
-
Save tomasr8/061590e1088591f42b9a056e83f41726 to your computer and use it in GitHub Desktop.
Javascript currying
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.prototype.curry = function(...args) { | |
const fn = this; | |
return function (...additional) { | |
return fn.apply(this, args.concat(additional)); | |
}; | |
}; | |
// examples | |
function greet(word, name) { | |
console.log(word, name); | |
} | |
let curried = greet.curry("Hello,"); | |
curried("John!"); | |
// -> "Hello, John!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment