I wanted to override the numberFruits property of the object fruits.
Tell me where is the error in the code?
var fruits = {}; Object.defineProperties(fruits, { "numberFruits": { value: 1, configuration: true }, "fruit": { get() { return this.numberFruits; }, set(value) { if(value >= 0 && value <=3) { Object.defineProperty(this, "numberFruits", { value: value }); } else { alert("Error!"); } }, enumerable: true } }); alert(fruits.fruit); fruits.fruit = 2; alert(fruits.fruit); 
this.numberFruits = {value}didn'tthis.numberFruits = {value}you? - vp_arthwritablereceived the valuefalse. Therefore, changing the value of a property is possible only viadefineProperty. If the error is removed from the code, of course. ) - Spomni