new instantiation design alternatives

Herby Vojčík herby at
Wed Sep 17 06:17:30 PDT 2014

Claude Pache <claude.pache at>napísal/a:

For instance, if I wanted to support to be called through the legacy `, ...args)` trick in addition to be new’d, I'd rather try the following:

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

Oh, this is really bulky.

Makes me think of fixing it by some slight magic. Like, adding modifier to method deginition to say it is a constructor (new keuword before opening left brace) and keeping stack of new^s in thread-local storage which wull be used in new-tagged methods, even if [[Call]]ed.

But that is not a nice solution at all. :-/

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


More information about the es-discuss mailing list