Skip to content

Latest commit

 

History

History
18 lines (14 loc) · 633 Bytes

new-target-explainer.md

File metadata and controls

18 lines (14 loc) · 633 Bytes

Quick new.target explainer

This design relies on the fact that the recent ES6 subclassing changes incorporate as a crucial ingredient a new parameter to the [[Construct]] internal method, which is the "original constructor" or "new-target." In summary:

class Base {
  constructor() {
    // not-quite-agreed-upon syntax for exposing the new-target
    console.log(new.target === Base);
    console.log(new.target === Derived);
  }
}

class Derived extends Base { }

new Base(); // true, false
new Derived(); // false, true