Exploring class Inheritance in Javascript


Classes can inherit from other classes.

Source Code

class Employee extends Person {
  constructor(name, position) {
    super(name);
    this.position = position;
  }
  showInfo() {
    console.log(`${this.name} works as a ${this.position}`);
  }
}
let employee = new Employee('Jane', 'Developer');
employee.greet(); // Hello, Jane
employee.showInfo(); // Jane works as a Developer
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments