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 这个错
求解
相关分类