I have noticed that using accessor properties instead of data properties in js then the object is forced to store the value of the property twice:
(我注意到在js中使用访问器属性而不是数据属性,然后该对象被强制存储两次该属性的值:)
let obj = {
get propName(){
return this._propName;
},
set propName(value){
this._propName = value;
}
}
obj.propName = "some_value";
for(let key in obj){
if((obj.hasOwnProperty(key)) && (typeof key != 'function')){
console.log(key + ": " + obj[key])
}
}
The output is:
(输出为:)
propName: some_value
_propName: some_value
I am right?
(我是正确的?)
ask by Arayik translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…