js object property get set
const obj = {
value: 0,
get prop() {
console.log(".prop accessed!");
return this.value;
},
set prop(newValue) {
console.log(".prop set! Value: ", newValue);
this.value = newValue;
}
}
console.log(obj.prop);
obj.prop = 42;
console.log(obj.prop);