Instantiate a JavaScript Object Using a String to Define the Class Name
Posted
by Kirk
on Stack Overflow
See other posts from Stack Overflow
or by Kirk
Published on 2009-09-02T06:34:55Z
Indexed on
2010/03/14
11:35 UTC
Read the original article
Hit count: 331
Here's what I'm trying to do -- this is pseudo code and doesn't work. Does anyone know how to accomplish this for reals:
// Define the class
MyClass = Class.extend({});
// Store the class name in a string
var classNameString = 'MyClass';
// Instantiate the object using the class name string
var myObject = new classNameString();
© Stack Overflow or respective owner