Hi all, I have a question about constructor()
and super()
syntax in sub-classes. If super
passes arguments of the parent class constructor, why is it ok to rename height
and width
to length
as in the following example?:
class Rectangle {
constructor(height, width) {
this.name = 'Rectangle';
this.height = height;
this.width = width;
}
sayName() {
console.log('Hi, I am a ', this.name + '.');
}
get area() {
return this.height * this.width;
}
set area(value) {
this._area = value;
}
}
class Square extends Rectangle {
constructor(length) {
super(length, length);
this.name = 'Square';
}
}
Isn’t the point of super
to exactly replicate a parent constructor’s properties?
Thanks!
L