Le 15 sept. 2014 à 23:19, Kevin Smith <zenpars...@gmail.com> a écrit :

> 
> 
> Isn't the latter (since it specifies ": super(x)") actually identical to
> 
>     constructor(x, y) {
>         this = new super();
>         this.y = y;
>     }
> 
> IOW, isn't it "I am constructor only and will throw if {[Call]]ed)?
> 
> No.  The idea is that the "class create expression" is only called when the 
> constructor is "new"d.  It's purpose is to set up the "this" value when 
> [[Construct]] is called, exactly as @@create used to.
> 

When you write:

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

is it intentional that you call the super-constructor only when you have been 
called with `new`, and not in case of a direct call?

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

    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.

—Claude


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

Reply via email to