So, suppose I have these two functions:
var foo = function() {
this.message = "fooBar";
this.fooBar = function() {
console.log(this.message);
};
};
and
var goo = function() {
this.message = "gooBar";
this.gooBar = function() {
console.log(this.message);
};
};
Then, suppose I have these two arrays:
var Foos = [];
var Goos = [];
And somewhere in the program, I push new instances of the corresponding function into the arrays (new foo into Foos, and new goo into Goos). Now, I want to call the methods. So, I could do this for Foos:
for(var i = 0; i < Foos.length; i ++) {
Foos[i].fooBar();
}
and then this for Goos:
for(var i = 0; i < Goos.length; i ++) {
Goos[i].gooBar();
}
When I have a lot of functions (which I do for my program), doing this gets a bit tedious. And my program also gives the functions more than one method. But some functions only have one. Yet others have five. So, I thought, why not use the Array object, like so:
Array.prototype.apply = function() {
for(var i = 0; i < this.length; i ++) {
this[i].CALL_METHODS();
}
};
Then I could store all the arrays in an array, and call apply on every element in that array. But, .CALL_METHODS() isn't an actual method (of course). So, is there any way that I can accomplish this, calling all the methods of instances, no matter the number of methods nor the names?
Thanks in advance!