archives

« Bugzilla Issues Index

#3562 — 12.3.5.1 NewSuper


Why does `new Super()` need the NewTarget of the current function environment?

class Derived extends Base {
constructor() {
var o = new Super();
// equivalent to
var o2 = new Base();

// With the current spec draft it is equivalent to
var o3 = Construct(Base, «», Derived)
}
}


I think it is that way:

class Derived extends Base {
constructor() {
var o = new super(); // Construct(Base, «», Derived)
// not equivalent to
var o2 = new Base(); // Construct(Base, «») === Construct(Base, «», Base)
}
}


exactly,

In a constructor that is [[Construct]] invoked, 'new super()' is semantically the same as 'super()' except that it doesn't throw if 'this' is already bound and it doesn't binding 'this' with its return value.

The third argument is the important thing. Also in your example, it isn't necessary 'Derived', it could be a subclass of 'Derived'


OK. Makes sense to me.