I have a String instance which contains the name of a class. Is there
some way I can instantiate that class from given the class name in the
string?
If you are trying to do what I think you are, there's a few ways you
can do it.
Here's two examples:
// set up the class
function MyClass() {
this.foo = "bar";
}
// store the class name in a string
var classIdString = "MyClass";
// first method
var classInstance = new this[classIdString];
// second method
var classInstance2 = eval("new "+ classIdString);
// test them
alert(classInstance.foo);
alert(classInstance2.foo);