Skip to content

Instantly share code, notes, and snippets.

@myogeshchavan97
Last active April 14, 2020 11:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myogeshchavan97/8ebfdbdfd9285820162af11a215e7290 to your computer and use it in GitHub Desktop.
Save myogeshchavan97/8ebfdbdfd9285820162af11a215e7290 to your computer and use it in GitHub Desktop.
Class Based Inheritance
class Person {
constructor(name, age) {
this.name = name;
this.age = age;
}
display() {
console.log(this.name, this.age);
}
}
class Employee extends Person {
constructor(name, age, salary) {
super(name, age); // call super class constructor
this.salary = salary;
}
}
const emp = new Employee('Mike', 20, 4000);
console.log(emp); // { name: 'Mike', age: 20, salary: 4000 }
emp.display(); // Mike 20
console.log(emp.constructor); // Employee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment