override constructor

✅ case 1:none has constructor

// no constructors
class A {}
class B extends A {}

let b = new B();        // ✅ OK

❌ case 2:returning from derived constructor without calling super() first

class A2 {}

class B2 extends A2 {
    constructor(){
        // ---------------------------------------------------
        // ⛔ ReferenceError: 
        //   Must call `super()` constructor in derived class 
        //   ☐ before accessing `this` or 
        //   ☑ returning from derived constructor
        // ---------------------------------------------------
    }
}

let b2 = new B2();

❌ case 3:accessing this before calling super()

✅ case 4:

Last updated

Was this helpful?