Created
August 22, 2020 12:17
-
-
Save iamsaief/31874a8bb33837573985fcc001869f2a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/* inheritance, extends, super */ | |
class Parent { | |
constructor() { | |
this.fatherName = "Christopher Nolan"; | |
this.motherName = "Emma Thomas"; | |
} | |
} | |
class Child extends Parent { | |
constructor(name, age) { | |
super(); | |
this.name = name; | |
this.age = age; | |
} | |
getFamily() { | |
return `Name: ${this.name}, Father: ${this.fatherName}, Mother: ${this.motherName}`; | |
} | |
} | |
const kid1 = new Child("Flora Nolan", 18); | |
const kid2 = new Child("Magnus Nolan", 12); | |
console.log(kid1.name); // Output : Flora Nolan | |
console.log(kid2.age); // Output : 12 | |
console.log(kid1.getFamily()); // Output: Name: Flora Nolan, Father: Christopher Nolan, Mother: Emma Thomas |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment