new instantiation design alternatives

Erik Arvidsson erik.arvidsson at gmail.com
Fri Sep 12 20:55:26 PDT 2014


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.
>
> -j
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140912/301ef499/attachment.html>


More information about the es-discuss mailing list