3
這裏的對象認定中:我如何遍歷一個對象,它使用的吸氣劑的JavaScript
var Vars = new function(){
var that = this;
this.assign = function(name) {
var realValue = undefined;
Object.defineProperty(that, name, {
configurable: true,
get: function() {
//console.log("Get"); do something...
return realValue;
},
set: function(v) {
//console.log("Set"); do something...
realValue = v;
}
});
}
this.destroy = function(name) {
return delete that[name];
}
};
但我發現我不能在這個對象由我所希望的方式進行迭代。
>> Vars.assign("key")
<- undefined
>> Vars.key = 1
<- 1
>> Vars.key
<- 1
>> for(var i in Vars){console.log(i);}
assign
destroy
<- undefined
當我迭代對象時,我怎麼能達到「關鍵」?
你需要'枚舉:TRUE'以及 – abhishekkannojia