I have a function that accepts a “type” of object for instantiation, out of a list of objects, if that objects constructor function does not exist yet, it declares it - and subsequently instantiates the specified number of that particular “type” of object:
the function is my idea of a video game spawner.
so, it works great, the only thing that confuses me is whether I need to put an if
statement before each of the Switch
case clauses [the code creating the constructor functions]. bc otherwise it will always declare that object “type”'s respective function, again, and again, and again, I am wondering whether I need to muddy my code by adding an if
statement or whether the JavaScript Engine is content just ignoring an already declared function declaration.
i know this is not super-great form but to put if
statements before each clause would look like a total nightmare and make the function unintelligible. i cannot put one before the Switch
statement because the Switch
clauses must always
be evaluated otherwise I cannot select the appropriate “type”