On Tue, Jun 17, 2014 at 3:21 PM, Jason Orendorff <jason.orendo...@gmail.com>
wrote:

> Allen asked me to fill out what @@new would mean. Here it is.
>

... snip ...


> The "super Arguments" call syntax in the ES6 drafts would be constrained to
> appear only at the top of a constructor, as in Java:
>
>     class PowerUp {
>         constructor(name, price) { ... }
>     }
>
>     class RocketPack extends PowerUp {
>         constructor() {
>             super("Rocket Pack", 1000);
>             this.fuel = FULL_TANK;
>         }
>     }
>
> The RocketPack constructor would behave like this:
>
>         static [Symbol.new]() {
>             var obj = super[Symbol.new]("Rocket Pack", 1000);
>             obj.fuel = FULL_TANK;
>             return obj;
>         }


How would

    constructor() {
        if (rand() > 0.5)
            super("A");
    }

behave? What about

    constructor() {
        if (0)
            super();
    }

?

This is a common trick in some languages that silently insert a super();
call if they didn't appear somewhere in the constructor to make sure that
super() is always called.

We could prevent this behavior by making sure that super(); must be the
first statement in a constructor, but that means that the subclass can't
really influence the parent constructor execution at all.

The other option is to ask users to always chain up in their constructor,
like they need to do in any other overridden method.

_______________________________________________
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>



-- 
  Jasper
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to