Advertisement
728x90
You can use the super keyword to call the constructor of a parent class. Remember that super() must be called before using this reference. Otherwise it will cause a reference error. Let's the usage of it,
javascript
1class Square extends Rectangle {
2 constructor(length) {
3 super(length, length);
4 this.name = "Square";
5 }
6
7 get area() {
8 return this.width * this.height;
9 }
10
11 set area(value) {
12 this.area = value;
13 }
14 }Advertisement
Responsive Ad
🎯 Practice NowRelated Challenge
JavaScript Coding Exercise 1
Test your knowledge with this interactive coding challenge.
Start CodingAdvertisement
728x90
258of476