87,901
社区成员
发帖
与我相关
我的任务
分享
var book={};
Object.defineProperties(book,{
_year:{
value:2004,
writable: true //当且仅当该属性的 writable 为 true 时,该属性才能被赋值运算符改变。默认为 false。
},
edition:{
value:1,
writable: true //当且仅当该属性的 writable 为 true 时,该属性才能被赋值运算符改变。默认为 false。
},
year:{
get:function(){
return this._year;
},
set:function(newValue){
if(newValue>2004){
this._year = newValue;
this.edition+=newValue -2004;
}
}
}
});
book.year=2005;
console.log(book.year);
console.log(book.edition);