new instantiation design alternatives

Jason Orendorff jason.orendorff at gmail.com
Fri Sep 12 15:39:18 PDT 2014


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.

-j


More information about the es-discuss mailing list