✅ Перевірена відповідь на це питання доступна нижче. Наші рішення, перевірені спільнотою, допомагають краще зрозуміти матеріал.
class AbstractShape {constructor() {
if (new.target === AbstractShape) {
throw new Error('Cannot instantiate abstract class');
}
}
area() {
throw new Error('Method area() must be implemented');
}
}
class Rectangle extends AbstractShape {
constructor(w, h) {
super();
this.w = w; this.h = h;
}
area() { return this.w \* this.h; }
}
const r = new Rectangle(4, 5);
console.log(r.area());