I'm wondering if this is a Chrome issue or it's by design (which would be inconsistent with all other objects in JavaScript).
Classes can't be instantiated dynamically like other objects. Consider this code:
class BaseClass {
}
And somewhere you want to dynamically create instance of this class:
var inst;
if (window[fnName].constructor) {
try {
inst = new window[fnName](value);
} catch (e) {}
} else {
inst = window[fnName](value);
}
Code from function above will fail (at leas in strict mode) because window object does not contain BaseClass. And this is not natural in JavaScript because defined objects / function are available in window object.
if I change the code to
return new BaseClass(value);
it is working as it should. So where classes definitions are kept? In global object? Not really. But they are available. Help me solve this.