1. Home
  2. Javascript
  3. Extend class

Extend an existing ES6 class. super() references the parent class constructor.

#javascript#es6
class ParentClass{    
    constructor(){
        // Constructor code
    }
    foo(){
        // Foo function code
    }
}

// Extend ParentClass
class ChildClass extends ParentClass{
    constructor(){
        // Super references the ParentClass constructor 
        super()
    }
    // Add here methods for the ChildClass
} 
copy
Full Javascript cheatsheet