Object.defineproperty 如何作用到类上或者说构造函数上 。试了下好像只能作用的对象实例上
function Person(name,age) { this._name=name this._age=age } Person.prototype.say=function(){ console.log(this._name) } let huixu = new Person('huixu',18) let lili = new Person('lili',25) Object.defineProperty(huixu,"_name",{value:'xxx'})//作用在对象实例上是有效的 //Object.defineProperty(Person,"_name",{value:'xxx'}) 无效 huixu.say()//huixu lili.say()//lili
慕斯王
相关分类