Skip to content

Instantly share code, notes, and snippets.

@Ghanshyam-K-Dobariya
Last active February 24, 2022 05:56
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 Ghanshyam-K-Dobariya/02bbe79aff279221ad66e548fe9982f8 to your computer and use it in GitHub Desktop.
Save Ghanshyam-K-Dobariya/02bbe79aff279221ad66e548fe9982f8 to your computer and use it in GitHub Desktop.
prototype_question_1.js
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