Skip to content

Instantly share code, notes, and snippets.

@iamsaief
Created August 22, 2020 12:17
Show Gist options
  • Save iamsaief/31874a8bb33837573985fcc001869f2a to your computer and use it in GitHub Desktop.
Save iamsaief/31874a8bb33837573985fcc001869f2a to your computer and use it in GitHub Desktop.
/* 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