I have the following classes
class Polygon {
constructor(height, width) {
this.height = height;
this.width = width;
}
}
class Square extends Polygon {
constructor(sideLength) {
super(sideLength, sideLength);
}
area() {
return this.height * this.width;
}
sideLength(newLength) {
this.height = newLength;
this.width = newLength;
}
}
and thei I create an instance of the class Square
var square = new Square(2);
My expectations were to find in the square object (directly in it and not in its prototype) the area
and sideLength
methods. Differently I find them in the __proto__
object.
I don't understand why it happens. Could you "translate" this same code using a constructor rather than a class? Maybe I will more easily get the point in this way...