Object.defineProperty()中get、set为什么不能和writable一起用会报错var obj = {}
Object.defineProperty(obj, 'name', {
configurable: true,
enumerable: true,
writable: true, value: 2, set(value) {
name = value
}, get() { return value
}
})
obj.name = 2console.log(obj.name)如上代码,会报 Cannot both specify accessors and a value or writable attribute 这个错求解
添加回答
举报
0/150
提交
取消