Skip to content

Instantly share code, notes, and snippets.

@hascode
Last active August 29, 2015 14:07
Show Gist options
  • Save hascode/09aae6197cc2f1fccdae to your computer and use it in GitHub Desktop.
Save hascode/09aae6197cc2f1fccdae to your computer and use it in GitHub Desktop.
Javascript Currying
Function.prototype.curry = function(){
var func = this, args = Array.prototype.slice.call(arguments);
return function(){
return func.apply(this, args.concat(Array.prototype.slice.call(arguments)));
}
};
var add = function(a,b){
return a+b;
}
console.log('add(2,3)=', add(2,3));
var increment = add.curry(1);
console.log('increment(4)=',increment(4));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment