I searched the web for some way to create instance of "Class" in "reflection" using javaScript but I found nothing.
generally i'm trying to do someting like java code.
Object o = Class.forename("MyClassName");
but in javaScript, in such way that I'll get the instance of class when I have only the name of the class, any idea?
Thankes.
JavaScript doesn't have classes. But if by "class" you mean you have a constructor function:
But the name of that function is in a variable:
Then you can instantiate an instance like this:
The above only works if
MyClassName
is in the global scope.Classes in Javascript are nothing but global functions. So you should be able to do this:
for example:
Keep in mind that this example is just an example. Arrays should be created via
[]
syntax.This is working for me: