Last active
February 24, 2022 05:56
-
-
Save Ghanshyam-K-Dobariya/02bbe79aff279221ad66e548fe9982f8 to your computer and use it in GitHub Desktop.
prototype_question_1.js
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
const nameObj = { | |
child: "c", | |
parents: "p", | |
grandParents: "gP", | |
}; | |
/* Code 1 | |
class GrandParent { | |
constructor({ grandParents }) { | |
this.grandParents = grandParents; | |
} | |
} | |
class Parents extends GrandParent { | |
constructor({ grandParents, parents }) { | |
super({ grandParents }); | |
this.parents = parents; | |
} | |
getGrandParentDetails() { | |
console.log(this.grandParents); | |
} | |
getParentDetails() { | |
console.log(this.parents); | |
} | |
getChildDetails() { | |
console.log(this.child); | |
} | |
getFamilyDetails() { | |
this.getChildDetails(); | |
this.getParentDetails(); | |
this.getGrandParentDetails(); | |
} | |
} | |
class Child extends Parents { | |
constructor({ grandParents, parents, child }) { | |
super({ | |
grandParents, | |
parents, | |
}); | |
this.child = child; | |
} | |
} | |
const c1 = new Child(nameObj); | |
c1.getChildDetails(); // | |
c1.getParentDetails(); // | |
c1.getGrandParentDetails(); // | |
c1.getFamilyDetails(); // | |
for (const key in c1) { | |
console.log(key); // | |
} | |
*/ | |
/* | |
code 2 | |
class GrandParent { | |
constructor({ grandParents }) { | |
this.grandParents = grandParents; | |
} | |
getGrandParentDetails() { | |
console.log(this.grandParents); | |
} | |
getParentDetails() { | |
console.log(this.parents); | |
} | |
getChildDetails() { | |
console.log(this.child); | |
} | |
} | |
class Parents extends GrandParent { | |
constructor({ grandParents, parents }) { | |
super({ grandParents }); | |
this.parents = parents; | |
} | |
} | |
class Child extends Parents { | |
constructor({ grandParents, parents, child }) { | |
super({ | |
grandParents, | |
parents, | |
}); | |
this.child = child; | |
} | |
getFamilyDetails() { | |
this.getChildDetails(); | |
this.getParentDetails(); | |
this.getGrandParentDetails(); | |
} | |
} | |
const c1 = new Child(nameObj); | |
c1.getChildDetails(); // | |
c1.getParentDetails(); // | |
c1.getGrandParentDetails(); // | |
c1.getFamilyDetails(); // | |
for (const key in c1) { | |
console.log(key); // | |
} | |
*/ | |
/* code 3 | |
class GrandParent { | |
constructor({ grandParents }) { | |
this.grandParents = grandParents; | |
} | |
getGrandParentDetails() { | |
console.log(this.grandParents); | |
} | |
} | |
class Parents extends GrandParent { | |
constructor({ grandParents, parents }) { | |
super({ grandParents }); | |
this.parents = parents; | |
} | |
getParentDetails() { | |
console.log(this.parents); | |
} | |
} | |
class Child extends Parents { | |
constructor({ grandParents, parents, child }) { | |
super({ | |
grandParents, | |
parents, | |
}); | |
this.child = child; | |
} | |
getChildDetails() { | |
console.log(this.child); | |
} | |
getFamilyDetails() { | |
this.getChildDetails(); | |
this.getParentDetails(); | |
this.getGrandParentDetails(); | |
} | |
} | |
const c1 = new Child(nameObj); | |
c1.getChildDetails(); // | |
c1.getParentDetails(); // | |
c1.getGrandParentDetails(); // | |
c1.getFamilyDetails(); // | |
for (const key in c1) { | |
console.log(key); // | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment