new instantiation design alternatives

Herby Vojčík herby at mailbox.sk
Mon Sep 15 13:43:57 PDT 2014



Kevin Smith wrote:
> Well, what I'm trying to point out is that it's always an error to set
> "this" if "new^" is undefined.  So it's kind of strange to force the
> user to explicitly write that conditional:
>
>      constructor(x, y) {
>          if (new^)
>              this = new super(x);
>          this.y = y;
>      }
>
> With the header approach, it's taken care of:
>
>      constructor(x, y) : super(x) {
>          this.y = y;
>      }
>
> (using colon just to avoid bikeshedding)

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)?

Herby


More information about the es-discuss mailing list