How do I dynamically instantiate a class in javascript?
- by Adam
I'm starting out with classes in Javascript and have hit a wall. I've looked all over for a tutorial that goes a little further than simply how to construct a class (usually Animal) then extend the class and have a Method do something (Dog alert('Bark');).
I have created a class that I want a user to be able to instantiate (is that the right word)? For example the first stage in my program is for the user to give the class a name, and then start to populate the various variables in the class. When they've done that they may do it again many times.
So if:
var className = new MyObject();
How do I dynamically create the name of the new object className and then refer to it later in the code?