I think you don't understand what you want. In JavaScript, there are no classes per se, you only have instances and
prototypes, which are all objects. JavaScript is a
prototype-based scripting language, which does support of object-oriented
style, which is not the same as classical object-oriented paradigm. All JavaScript objects are nothing but associative arrays/dictionaries.
See:
http://en.wikipedia.org/wiki/JavaScript[
^],
http://en.wikipedia.org/wiki/JavaScript#Prototype-based[
^].
When you say "invoke
myMethod
of each of these derived classes, it assumes that
myMethod
is a
static method of classic OOP, otherwise it would requires some set of instances to be passed as "this" reference in each call. In JavaScript, there are no such things. You just have some set of object, and each of them may or may not have such method.
That said, whenever you need to invoke some set of calls of some method, you simply need a set of objects (not classes!) to call it. To have such set, you need to put your objects in some container, traverse it in
for… in…
loop and call the method for each object. Be ready to catch exception if the call fails.
The question about good a bad practice does not really make sense as you meant something else. There is nothing wrong with calling a method in the loop; the question of performance also makes little to know sense as it's unclear what to consider as an alternative and what's the purpose of it.
—SA