JSFiddle - React, Tailwind, and code Playground
by Maxim_Wolf
JavaScript
class Shape {
constructor(){
this._area = undefined;
}
/*protected*/ computeArea(){
throw new Error('you cannot get the area value of some abstract shape')
}
/*public */ get area(){
if(typeof this._area === 'undefined'){
this._area = this.computeArea();
}
return this._area;
}
}
class Square extends Shape{
constructor(side){
super();
this.side = side
}
computeArea(){
return this.side * this.side;
}
}
const instance = new Square (10);
console.log (instance.area);