これが私のコードです:
TextClass = function () {
this._textArr = {};
};
TextClass.prototype = {
SetTexts: function (texts) {
for (var i = 0; i < texts.length; i++) {
this._textArr[texts[i].Key] = texts[i].Value;
}
},
GetText: function (key) {
var value = this._textArr[key];
return String.IsNullOrEmpty(value) ? 'N/A' : value;
}
};
Underscore.js ライブラリを使用しており、SetTexts 関数を次のように定義したいと考えています。
_.each(texts, function (text) {
this._textArr[text.Key] = text.Value;
});
しかし、ループに入ると _textArr は未定義です。