[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Errors/Super_not_called [Back]  [Original]

ReferenceError: must call super constructor before using 'this' in derived class constructor - JavaScript | MDN

MDN Web Docs

View in English Always switch to English

ReferenceError: must call super constructor before using 'this' in derived class constructor

JavaScript "must call super constructor before using 'this' in derived class constructor" super() this

ReferenceError: Must call super constructor in derived class before accessing 'this' or returning from derived constructor (V8-based)
ReferenceError: must call super constructor before using 'this' in derived class constructor (Firefox)
ReferenceError: 'super()' must be called in derived constructor before accessing |this| or returning non-object. (Safari)

ReferenceError

super() new 1 1 this this this this super()

js
class Base {
  constructor() {
    this.x = 1;
  }
}

class Derived extends Base {
  constructor() {
    console.log(this.x);
    //  Base this.x 
    // ReferenceError: must call super constructor before using 'this' in derived class constructor
  }
}

js
class Base {
  constructor() {
    this.x = 1;
  }
}

class Derived extends Base {
  constructor() {
    super();
    console.log(this.x); // 1
  }
}


Web Proxy Viewer  |  New URL  |  Original Page