160
rated 0 times
[
167]
[
7]
/ answers: 1 / hits: 27097
/ 11 Years ago, fri, october 18, 2013, 12:00:00
I'm iterating through an array using forEach in one of my Class's methods. I need access to the instance of the class inside the forEach but this is undefined.
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();
I have a fiddle I'm working on here: http://jsfiddle.net/NhdDS/1/ .
More From » javascript