const people = {
year: 1,
_time: 2005
}
Object.defineProperty(people, "time", {
get: () => {
return this._time;
},
set:(value) => {
this._time = value;
this.year += value - 2005;
}
})
people.time = 2018;
console.log(people.time);
console.log(people.year)
const book = {
_year: 2004,
edition: 1
};
Object.defineProperty(book, "year", {
get: function() {
return this._year;
},
set: function(newValue) {
this._year = newValue;
this.edition += newValue -2004;
}
})
book.year = 2015;
console.log(book.edition);
console