Last active
August 29, 2015 14:07
-
-
Save hascode/09aae6197cc2f1fccdae to your computer and use it in GitHub Desktop.
Javascript Currying
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
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