Last active
April 14, 2020 11:40
-
-
Save myogeshchavan97/8ebfdbdfd9285820162af11a215e7290 to your computer and use it in GitHub Desktop.
Class Based Inheritance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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