Scoped binding of a method to an object
Benjamin (Inglor) Gruenbaum
inglor at gmail.com
Sun Oct 13 14:56:56 PDT 2013
Rick Waldron <waldron.rick at gmail.com> wrote:
> That's incorrect. XArray.prototype.map would return an XArray instance
and reduce always returns what you specify it to return, which can be
Domenic Denicola <domenic at domenicdenicola.com> wrote:
>This is actually not true as of ES6; ES6 uses `this.constructor` to figure
out how to create the returned instance, which means inherited versions of
`map`/`reduce`/etc. will automatically return new `XArray`s.
That actually covers one of the primary use cases I see then. It doesn't
solve the problem fully but it does make life a lot easier when trying to
extend the natives.
On Mon, Oct 14, 2013 at 12:50 AM, Domenic Denicola <
domenic at domenicdenicola.com> wrote:
> From: es-discuss [mailto:es-discuss-bounces at mozilla.org] On Behalf Of
> Benjamin (Inglor) Gruenbaum
> > not to mention stuff like `.map` or `.reduce` would still return an
> Array which would result in more endless wrapping.
> This is actually not true as of ES6; ES6 uses `this.constructor` to figure
> out how to create the returned instance, which means inherited versions of
> `map`/`reduce`/etc. will automatically return new `XArray`s.
> It's quite a clever trick IMO, so we should all thank Allen for pushing
> for it and doing the spec work to make it possible :)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss