Created
March 6, 2018 07:54
-
-
Save kyontan/8a24a78ef04f46cbce1bf7cb898d50ae to your computer and use it in GitHub Desktop.
yield_self in JavaScript (ECMAScript)
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
Object.defineProperty(Array.prototype, 'yield_self', { | |
enumerable: false, | |
value: function(f) { return f(this); } | |
}); | |
// > array | |
// [ 1, 2, 3 ] | |
// > array.yield_self(x => x.concat(x)) | |
// [ 1, 2, 3, 1, 2, 3 ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment