我正在尝试填充字典(JavaScript 对象)并使用字符串索引从中检索值。undefined
出于某种原因,当我尝试检索值时它总是返回。
我的代码是这样的:
var _gauges = {};
//fill the gauges
_gauges[gaugeName] = gaugeObject;
然后我尝试按如下方式访问它:
setValue: function (gaugeName, newValue) {
var thisGauge = _gauges[gaugeName]; //always undefined
console.log(_gauges); //output shows all the elements that were added to _gauges
if (thisGauge) {
thisGauge.setCell(0, 1, newValue);
}
}
我在这里做错什么了吗?