Answer the question
In order to leave comments, you need to log in
Inheritance chain how?
Hey! Can you please tell me how to implement type inheritance from SomePencil to AnotherPencil? Thanks
class Pencil {
constructor(color) {
this.color = color;
}
intro() {
console.log(`this is ${this.color} pencil`);
}
};
class SomePencil extends Pencil {
constructor(color, type) {
super(color);
this.type = type;
}
};
class AnotherPencil extends SomePencil {
constructor(color,) {
super(color);
}
};
let pen1 = new Pencil();
let pen2 = new SomePencil("red", "common");
let pen3 = new AnotherPencil("green");
console.log("type" in pen3); // true
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question