Created
May 16, 2010 14:56
-
-
Save godfat/402911 to your computer and use it in GitHub Desktop.
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(){ | |
var slice = Array.prototype.slice, | |
args = slice.apply(arguments), | |
that = this | |
return function(){ | |
var aa = args.concat(slice.apply(arguments)) | |
if(that.arity == aa.length) | |
return that.apply(null, aa) | |
else | |
return Function.prototype.curry.apply(that, aa) | |
} | |
} | |
g = function(a, b, c){ print(a, b, c) } | |
f = g.curry() | |
f(1)(2)(3) | |
f(1,2)(3) | |
f(1)(2,3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment