使用Object.defineProperty() 定義對象屬性時,如已設置 set 或 get, 就不能設置 writable 和 value 中的任何一個了,不然會報如下錯誤:
TypeError: Invalid property descriptor. Cannot both specify accessors and a value or writable attribute, #<Object>
at Function.defineProperty (<anonymous>)
at Object.<anonymous> (/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代理了。