1. Home
  2. Javascript
  3. Extend class
#javascript#es6

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

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
Sitemap Git repository