Consider the following code:
var x = 0;
var o = {};
function getter() {
return x;
}
Object.defineProperty(o, "y", {
get: getter,
set: function (y) {
x = y;
Object.defineProperty(o, "y", {
get: getter
});
},
configurable: true
});
My objective is to remove the setter and make the property o.y
non-configurable after the setter has been called once. However it doesn't work as expected:
> x // 0
> o.y // 0
> o.y = 1 // 1
> x // 1
> o.y // 1
> o.y = 2 // 2
> x // 2
> o.y // 2
So my code did not work as expected, and I can't think of any other solution. Hence this question.
nextProps
) unmodifiable. – Cahill