new instantiation design alternatives

Allen Wirfs-Brock allen at wirfs-brock.com
Sun Sep 14 12:16:12 PDT 2014


On Sep 12, 2014, at 8:55 PM, Erik Arvidsson wrote:

> 
> On Sep 12, 2014 6:39 PM, "Jason Orendorff" <jason.orendorff at gmail.com> wrote:
> >
> > On Thu, Sep 11, 2014 at 4:15 PM, Allen Wirfs-Brock
> > <allen at wirfs-brock.com> wrote:
> > > `new^` is lexically scoped, just this `this` and `super`.  If an arrow
> > > function references `new^` it is the value of the closest lexically
> > > enclosing constructor function (a function that implements [[Construct]]).
> > >
> > > Just like [[Get]] and [[Set]], the trap for [[Construct]] is extended to
> > > include a "receiver" parameter.
> >
> > Thanks. The analogy to [[Get]] and [[Set]] helps a lot.
> >
> > (Superficially, possible alternatives to `new^` could include
> > `class()` and `class this`.)
> >
> > One more minor question. Suppose I mistakenly type:
> >
> >     class ColorPoint extends Point {
> >         constructor(x, y, color) {
> >             this = super(x, y); // oops: should be `new super(x, y)`
> >             this.color = color;
> >         }
> >     }
> >
> > Then `new ColorPoint(0, 0, "red")` throws a ReferenceError, because
> > `super(x, y)` implicitly uses `this`. Is that right? Asking just
> > because it seems like it'd be an easy mistake to make.
> 
> It will [[Call]] Point instead of [[Construct]] which may or may not work depending on how Point is defined.
> >
> 

No, Jason was correct.  It would get a Reference Error because `super(x,y)` implicitly tries to pass `this` which is still in its TDZ.

Allen 

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


More information about the es-discuss mailing list