错误合集-Cannot both specify accessors and a value or writable attribute,

使用Object.defineProperty() 定义对象属性时,如已设置 set 或 get, 就不能设置 writable 和 value 中的任何一个了,不然会报如下错误:

TypeError: Invalid property descriptor. Cannot both specify accessors and a value or writable attribute, #
    at Function.defineProperty ()
    at Object. (/Users/mac/Documents/GitHub/the-red-book-note/双向绑定/test.js:2:8)
    at Module._compile (internal/modules/cjs/loader.js:956:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
    at Module.load (internal/modules/cjs/loader.js:812:32)
    at Function.Module._load (internal/modules/cjs/loader.js:724:14)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1025:10)
    at internal/main/run_main_module.js:17:11

因为不再需要value和writable的属性了,所有关于value的操作都由get和set代理了。

你可能感兴趣的:(错误合集)