How do I dynamically instantiate a class in javascript?
Posted
by Adam
on Stack Overflow
See other posts from Stack Overflow
or by Adam
Published on 2010-05-03T02:28:27Z
Indexed on
2010/05/03
2:38 UTC
Read the original article
Hit count: 355
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?
© Stack Overflow or respective owner