class, super, constructor (ok)

https://js.edu.vn/7-ke-thua-prototype-ngang-va-doc.html

'use strict';
class Polygon {
	constructor(height, width) {
		this.height = height;
		this.width = width;
	}
}
class Square extends Polygon {
	constructor(sideLength) {
		super(sideLength, sideLength);
	}
	get area() {
		return this.height * this.width;
	}
	set sideLength(newLength) {
	  this.height = newLength;
	  this.width = newLength;
	}
}
var square = new Square(2);
console.log(square);

Last updated

Navigation

Lionel

@Copyright 2023