1class Rectangle {
2 constructor(height, width) {
3 this.name = 'Rectangle';
4 this.height = height;
5 this.width = width;
6 }
7 sayName() {
8 console.log('Hi, I am a ', this.name + '.');
9 }
10 get area() {
11 return this.height * this.width;
12 }
13 set area(value) {
14 this._area = value;
15 }
16}
17
18class Square extends Rectangle {
19 constructor(length) {
20 this.height; // ReferenceError, super needs to be called first!
21
22 // Here, it calls the parent class's constructor with lengths
23 // provided for the Rectangle's width and height
24 super(length, length);
25
26 // Note: In derived classes, super() must be called before you
27 // can use 'this'. Leaving this out will cause a reference error.
28 this.name = 'Square';
29 }
30}