@@new

Jasper St. Pierre jstpierre at mecheye.net
Tue Jun 17 17:41:28 PDT 2014


On Tue, Jun 17, 2014 at 4:02 PM, Jason Orendorff <jason.orendorff at gmail.com>
wrote:

> On Tue, Jun 17, 2014 at 2:49 PM, Jasper St. Pierre
> <jstpierre at mecheye.net> wrote:
> > How would
> >
> >     constructor() {
> >         if (rand() > 0.5)
> >             super("A");
> >     }
> >
> > behave?
>
> SyntaxError.
>
> > We could prevent this behavior by making sure that super(); must be the
> > first statement in a constructor, [...]
>
> That is what I proposed.
>

What does:

    class B {
        constructor(a) {
            this._a = a;
        }
    }

    class C extends B {
        constructor(b) {
            this._b = b;
        }
    }

do? Some kind of compiler error?

> [...] but that means that the subclass can't
> > really influence the parent constructor execution at all.
>
> Any class can explicitly define a `static [Symbol.new]()` method, if
> desired.
>
> Or the constructor method can return another object, so that the base
> class @@new method is called, but the object it created is thrown
> away. I should have mentioned that -- I would retain this behavior,
> which is already in ES6, but none of the examples used it so I forgot
> to say so.
>
> Anyway --- skipping a base class constructor is not a normal thing to
> do. It shouldn't be the default.
>
> -j
>



-- 
  Jasper
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140617/fd68a7b3/attachment.html>


More information about the es-discuss mailing list