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