Object.defineProperty()中g(shù)et、set為什么不能和writable一起用會(huì)報(bào)錯(cuò)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)如上代碼,會(huì)報(bào) Cannot both specify accessors and a value or writable attribute 這個(gè)錯(cuò)求解
Object.defineProperty()中g(shù)et、set為什么不能和writable一起用?
呼喚遠(yuǎn)方
2018-09-08 10:47:34