Skip to content

Instantly share code, notes, and snippets.

@kyontan
Created March 6, 2018 07:54
Show Gist options
  • Save kyontan/8a24a78ef04f46cbce1bf7cb898d50ae to your computer and use it in GitHub Desktop.
Save kyontan/8a24a78ef04f46cbce1bf7cb898d50ae to your computer and use it in GitHub Desktop.
yield_self in JavaScript (ECMAScript)
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