This question already has an answer here:
Object.assign getters and setters in constructor (1 answer)
Closed 3 years ago.
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);
Run code snippetExpand snippet
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.
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)