I have an object of type bar which has an Array of many foos.
I want to be able to call a method of foo dynamically - I could do this with eval by passing a string, but I would rather get a handle on how to pass the function.
Am I - conceptually - doing this the right way?
var foo = function() {
this.methodA = function() {
return "a";
};
this.methodB = function() {
return "b";
};
};
var bar = function() {
var foos = [];
this.construct = function() {
foos[0] = new foo();
}; this.construct();
this.callFoo = function(f) {
return foos[0].f();
};
};
b = new bar();
b.callFoo(foo.methodA); //<-- This doesn't work
b.callFoo(methodA); //<-- Or this