Store the current this
in some other variable in Chart
like this
function Chart() {
var self = this;
this.draw = function(data) {
data.forEach(function(value) {
//do something with values
console.log(self);
});
}
};
Also, you can pass the this
like the following, as Array.prototype.forEach
accepts this
arr.forEach(callback[, thisArg])
For example,
this.draw = function(data) {
data.forEach(function(value) {
//do something with values
console.log(this);
}, this); // Pass the current object as the second parameter
}