var book = {
year:2004,
edition:1
}
Object.defineProperty(book,"year",{
get:function(){
return this.year
},
set:function(newVal){
if(newVal>2004){
this.year = newVal ;
this.edition += newVal - 2004 ;
}
}
});
book.year = 2005 ;
console.log(book.edition)
如上所示,直接运行会报错 Maximum call stack size exceeded
at Object.set [as year]
但是如果在year前面加个标识符或者别的字母,就没什么问题,哪位可以解答一下?
心有法竹
ITMISS
相关分类