In the following object, I have a problem using the 'this' reference:
function SampleObject(){
this.addObject = function(object){...}
...
// more code here
...
this.addNewObjects= function(arr){
arr.forEach( function (obj) {
this.addObject(new Obj(obj.prop1, obj.prop2));
});
}
}
I'm assuming the context is changing and that 'this' refers the iterated 'obj', and not 'SampleObject'. I've solved the problem using a normal for loop however, i'm curuois to why this is not working, and would like to know if there is another way to do this.