Skip to content

Instantly share code, notes, and snippets.

@tomasr8
Last active August 16, 2016 12:06
Show Gist options
  • Save tomasr8/061590e1088591f42b9a056e83f41726 to your computer and use it in GitHub Desktop.
Save tomasr8/061590e1088591f42b9a056e83f41726 to your computer and use it in GitHub Desktop.
Javascript currying
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