Instance bound class methods
Domenic Denicola
d at domenic.me
Mon Jul 13 15:27:36 UTC 2015
From: es-discuss [mailto:es-discuss-bounces at mozilla.org] On Behalf Of Brendan Eich
> You're counting on the property assignment being moved into the constructor, where `this` is bound. In a class body in ES6 (without property assignment extension), especially in the top level where method defintiions go, `this` isn't obviously bound to the newly constructed instance.
>
> Ok, that's kind of a nit, or an observation. No worries.
Yeah, just to highlight this, the property initializer syntax is very far from reaching consensus, and I wouldn't take that for granted and then ask if we can build something else on top of it.
> Bigger question is what we want: method per instance allocation cost, which what you did imposes? Or something that can be more efficiently implemented, such as what Strong/SoundScript proposes (last I looked).
> The latter is what Java and C++ do. Then the trick is enabling first-class function extraction from method, which is a pay-for-what-you-ask-for alternative to allocation per method per constructed instance.
Agreed. The pattern shown is really an antipattern in my book (and according to conventional JavaScript wisdom). My understanding is that React encourages this antipattern, but that's not something we should encourage at a language level. (Which is part of why property initializer syntax may not make it, at least not in the form you show).
More information about the es-discuss
mailing list