我在我的一个Class方法中使用forEach迭代一个数组.我需要访问在foreach内部的类的实例,但是这是不确定的.
var aGlobalVar = {};
(function () {
"use strict";
aGlobalVar.thing = function() {
this.value = "thing";
}
aGlobalVar.thing.prototype.amethod = function() {
data.forEach(function(d) {
console.log(d);
console.log(this.value);
});
}
})();
var rr = new aGlobalVar.thing();
rr.amethod();
Run Code Online (Sandbox Code Playgroud)
我有一个小提琴,我在这里工作:http://jsfiddle.net/NhdDS/1/.
javascript ×1