JS6, Browser
How to create the instance of the class by its string name? For example I have a string Foo
and I need to create an instance of Foo
class. I don't want to write such construction:
let className = getClassName(); // returns 'Foo', `Stuff` or other
...
let item = null;
if(`Foo` == className){
item = new Foo();
}
else if(`Stuff` == className){
item = new Stuff();
}
UPD
I try to get access to my class constructor through the window
object but I have the problem: it returns undefined
. But my class exists and browser knows it: