setters code greeper
// this is an example of setters and getters of javascript classes
class Square {
constructor(width){
this.width = width ;
this.height = width ;
this.numOfRequests = 0;
}
get area(){
this.numOfRequests ++ ;
return this.width * this.height ;
}
set area(area){
this.width = Math.sqrt(area);
this.height = Math.sqrt(area);
}
}
const newSquare = new Square(6);
console.log(newSquare.area);
console.log(newSquare.area);
console.log(newSquare.area);
console.log(newSquare.area);
console.log(newSquare.area);
console.log(newSquare.area);
console.log(newSquare.area);
console.log(newSquare.numOfRequests);