I got an error while use this code
var book = {
year: 2004,
edition: 1
};
Object.defineProperty(book, "year", {
get: function(){
return this.year;
},
set: function(newValue){
if (newValue > 2004) {
this.year = newValue;
this.edition += newValue - 2004;
}
}
});
book.year = 2005;
alert(book.edition);
The warning told me that the error happened at Object.set [as year]this.year = newValue;
I am confused that why setting the year will cause this error?