I'm having an odd error with a JS object, it goes like this:
function MatchManager(){
this.current_m = [];
}
MatchManager.prototype.addMatchBatch = function (array){
// yes I could do an apply..
for(var i = 0; i < array.length; i++){
this.current_m.push(array[i]);
}
}
However, when I call addMatchBatch
on an instance of MatchManager
I get Cannot read property 'push' of undefined
. Which means that current_m is not being recognized by the Instance.
I also tried adding var parent=this;
and changing this
by parent
inside the for
loop, to no avail.
I'm guessing this
references the addMatchBatch function instead of the Instance... how do I overcome this?
If anyone has any idea why, I will be very grateful!
Thanks a lot!
PS: I'm calling and instantiating my objects like so:
MatchManager.prototype.getCurrent = function(){
var options : {
url : myUrl,
method: "GET",
callback: this.addMatchBatch
};
AJAXCall(options);
}
var manager = new MatchManager();
manager.getCurrent();