I'm currently working on implementing a model in JavaScript in an object-oriented manner. I have an object X that contains several functions, and I would like to create an object array "in X" where some of its fields reference functions within X. Here's an example of what I've attempted:
function X(){
this.open = function(e){...};
this.run = function(e){...};
this.close = function(e){...};
//...
this.STATES = {
1: {name : "opening", applyAction : this.open},
2: {name : "running", applyAction : this.run},
3: {name : "closing", applyAction : this.close},
//...
};
this.currentState = this.STATES[1];
//...
this.update = function(e){
//...
currentState.applyAction(e);
//...
}
}
Unfortunately, this approach is not functioning as expected. I am struggling to identify the issue, so if you have an alternative method for achieving the same outcome, your suggestions are greatly appreciated.