Created
January 11, 2016 17:22
-
-
Save thurt/6a8a55db4be4b6b53e03 to your computer and use it in GitHub Desktop.
uncurrying() in JavaScript.
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.uncurrying = function() { | |
| var _this = this; | |
| return function() { | |
| return Function.prototype.call.apply(_this, arguments); | |
| }; | |
| }; | |
| /*var push = Array.prototype.push.uncurrying(); | |
| var a = []; | |
| push(a, 1, 2, 'zensh'); | |
| console.log(a); | |
| var concat = String.prototype.concat.uncurrying(); | |
| var b = concat('Hello,', 'zensh!'); | |
| console.log(b);*/ |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is an ES6 version to consider:
The first parameter to #call is the intended
thisvalue.In the case of
push(a, 1, 2, 'zensh'), theaarray will be thethisvalue.In the case of
concat('Hello,', 'zensh!'), the'Hello'will be thethisvalue. However,thismust be an object so'Hello'is implicitly converted to an object using the String object wrapper.