JavaScript setter updates the internal value at the reference but the return value is not correct.
var Game =
{
get points() {
return this._points;
},
set points(x){
x = Math.min(x,25);
this._points = x;
return this._points;
}
};
Game.points = 10 ;
console.log(Game.points); // outputs 10
var updatedPoints = (Game.points = 60);
console.log(updatedPoints); // outputs 60
console.log(Game.points); // outputs 25
Expected value for 'updatedPoints' was 25 !
Any idea why this could be happening ? Can you suggest if there is a way to fix this ?
Reason to fix this: To make sure the JS code performs as expected , maintainibility !