Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

JavaScript super() keyword

// parent class
class Person { 
    constructor(name) {
        this.name = name;
    }
    greet() {
        console.log(`Hello ${this.name}`);
    }
}
// inheriting parent class
class Student extends Person {
    constructor(name) {
            console.log("Creating student class");
                // call the super class constructor and pass in the name parameter
        super(name);
    }
}
let student1 = new Student('Jack');
student1.greet();
Source by developer.mozilla.org #
 
PREVIOUS NEXT
Tagged: #JavaScript #keyword
ADD COMMENT
Topic
Name
1+7 =