请 da shen 帮我看一下代码

clipboard.png
请问这段代码有什么问题,console.log出来的为什么是1,为什么不是3?

阅读 1.9k
2 个回答

defineProperties如果不显式指定变量的属性描述符为true,那么这些属性enumerable、configurable、writable属性默认都是false,即不可枚举,不可删除,不可修改

Object.defineProperties(book,{
    _year:{
            value:2004,
            writable:true
        },
    edition:{
            value:1,
            writable:true
            },
    year:{
        get:function(){
            return this._year;
        },
        set:function(newValue){
            if(newValue > 2004){
                this._year = newValue;
                this.edition += newValue - 2004;
            }
        }
    }
})
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题