I try to setup an instance dynamically from a string. I've read many questions about it but the answers does not work for me.
It says it's possible to use window
before the name to set the instance. It does not work.
class MyClass {
// Something useful
}
let params = {};
let name = 'MyClass';
let instance = new window[name](params);
I've also tried to do this without luck (throws error):
let instance = new window['MyClass'](params);
However, this works:
let instance = new MyClass(params);
Why can't I use window
in this case? Any other ideas?