Instance bound class methods
d at domenic.me
Fri Jul 17 23:17:57 UTC 2015
I don't think this is possible to do in a memory-efficient way. I thus think it should not be easy, nor concise. Doing inefficient things should be painful and discouraged.
From: Sebastian Markbåge [mailto:sebastian at calyptus.eu]
Sent: Friday, July 17, 2015 19:14
To: Domenic Denicola
Cc: Matthew Robb; es-discuss at mozilla.org >> es-discuss
Subject: Re: Instance bound class methods
Domenic, would you care to propose an alternative that is concise and memory efficient if it is an anti-pattern?
That would be helpful and constructive (your comment, not so much).
> On Jul 13, 2015, at 8:27 AM, Domenic Denicola <d at domenic.me> wrote:
> 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.
> es-discuss mailing list
> es-discuss at mozilla.org
More information about the es-discuss