I stumbled upon code similar to this in modern JavaScript:
let obj = {
data: {number: 9},
set prop(p) {
this.data = p;
},
get prop() {
return this.data;
}
};
obj = Object.assign({}, obj, {
data: {number: 2}
});
console.log('obj.data === obj.prop ', obj.data === obj.prop);
console.log('obj.data.number === obj.prop.number ', obj.data.number === obj.prop.number);
Any modification is done outside of the computed property, as if there were none.
I was expecting the computed property to still exist.
Is there a way to preserve the computed property after a call to Object.assign
? Thanks.