Dmitry Soshnikov dmitry.soshnikov at gmail.com
Tue Jun 17 14:24:47 PDT 2014

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

> 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.
Ouch.. Don't know, there are several valid semantics. I don't know about
Java (as you say it's enforces calling parent constructor automatically,
and allows only on top of the child constructor), but there are other valid
semantics (Python, Ruby, etc), that don't force this restriction.

Does it make implementation's simpler? I think the main driver should be
developers life, not the implementation.

> > We could prevent this behavior by making sure that super(); must be the
> > first statement in a constructor, [...]
> That is what I proposed.
> > [...] 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.
That's the question. I guess there could valid cases when you wanna call
parent constructor conditionally as was shown, or to call it after prologue
initialization (which probably would set some default props needed for the
parent ctor) in the child constructor.

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

More information about the es-discuss mailing list