new instantiation design alternatives

Domenic Denicola domenic at domenicdenicola.com
Wed Sep 17 06:59:35 PDT 2014



On Sep 17, 2014, at 6:40, "Kevin Smith" <zenparsing at gmail.com<mailto:zenparsing at gmail.com>> wrote:


    constructor(x, y) {
        if (new^)
            this = new super(x);
        else
            super.constructor(x);
        this.y = y;
    }

The point here is that the purpose of the constructor method is not only allocation, but also (and primarily) initialisation.

Yes - you are right.  And I think we can safely assume that users will refuse to write such boilerplate.

That seems fine. Enabling different behaviour for called vs. constructed should only be used to explain the builtins; user code should not do so themselves. So it makes sense to me that those trying to do that would get "punished" with having to type more.

The more pressing ergonomic question is whether `this = new super(...)` is too much. I think it's fine, especially in comparison to `Base.call(this, ...)`. (For those counting characters, the score comes down to how long your superclass name is, and I'd wager most are longer than the five characters required for the new syntax to start winning.)

I'll have to consider things for a bit before replying to the larger point.

_______________________________________________
es-discuss mailing list
es-discuss at mozilla.org<mailto:es-discuss at mozilla.org>
https://mail.mozilla.org/listinfo/es-discuss
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140917/9356f5ca/attachment-0001.html>


More information about the es-discuss mailing list