I am writing some javascript that does the following:
- The main function creates a "ModelState" instance called "currentState".
- The "currentState" object creates a "LabScene" instance called "scene".
- The scene then tries to execute a callback to "currentState" passing itself as an argument.
- I get the following error:
Uncaught TypeError: Cannot read property 'push' of undefined at ModelState.dirtyListCallback (Test.js:16)
The code is below:
function main(){
//load state
var currentState = new ModelState();
}
function ModelState(){
this.dirtyList = [];
//initialize the scene.
this.scene = new LabScene(this.dirtyListCallback);
}
ModelState.prototype.dirtyListCallback = function(dirtyObject){
this.dirtyList.push(dirtyObject);
console.log(this.dirtyList);
};
function LabScene(dirtyListCallback){
dirtyListCallback(this);
}
I expected the currentState object to store the scene object in the dirtyList array. But that is not happening. This is part of a much larger code base in which child objects are expected to identify themselves as "dirty" (needs to be re-drawn) to their parent. Any help would be appreciated.