Created
May 28, 2013 12:50
-
-
Save luin/5662549 to your computer and use it in GitHub Desktop.
JavaScript反柯里化
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.unCurrying = function () { | |
var self = this; | |
return function () { | |
var args = Array.prototype.slice.call(arguments); | |
return self.apply(args[0], args.slice(1)); | |
}; | |
}; | |
var foo = []; | |
var push = Array.prototype.push.unCurrying(); | |
var slice = Array.prototype.slice.unCurrying(); | |
var join = Array.prototype.join.unCurrying(); | |
push(foo, 'first'); | |
push(foo, 'second'); | |
push(foo, 'third'); | |
console.log(join(foo, ', ')); | |
console.log(foo); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment