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,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
class Square extends Rectangle { constructor(length) { super(length, length); this.name = 'Square'; } get area() { return this.width * this.height; } set area(value) { this.area = value; } } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.