I want to make a class in node that runs a set of stages that can be easily added or removed. My current code looks like this:
function MyClass(){
this._stages = [this.function1, this.function2];
this._info = {'a':'special object info'};
};
MyClass.prototype.run = function(){
for(var i = 0; i<this._stages.length; i++){
this._stages[i]();
}
};
MyClass.prototype.function1 = function(){
this.subfunction1();
};
MyClass.prototype.subfunction1 = function(){};
Unfortunately, it seems like putting the function inside the Array
messes up their 'parent', and I get an error saying that
TypeError: Object function (query) {
[...long list of elements]
} has no method 'subfunction1'
at Array.MyClass.function1...
Is there a way to accomplish this by-stage execution without having this happen?
Thanks!