如题,Obejct.defineProperty到底做了什么事情,会将实例上对应的属性也屏蔽掉class List { constructor() { this.members = [...arguments] this.length = this.members.length this.pos = 0 console.log(this.length) } } Object.defineProperty(List.prototype, 'length', { get() {return this.members.length + 1}, set() {}, enumerable: false, configurable: false, }) let myList = new List('Jack', 'Rose', 'Tom') console.log(myList.length) // 4
添加回答
举报
0/150
提交
取消