I am working with webpack, typescript 2.8, es5.
I want to create dynamic class instances from variable names for example:
protected handleAfterInit(page) : void
{
let instance: any;
let pageName: string = this.capitalizeFirstLetter(page);
console.log(pageName);
instance = Object.create((window[pageName]).prototype);
instance.constructor.apply(instance);
console.log(instance);
}
Where pageName is a variable (Home, About etc) and those classes are already imported on top of the page:
import { Home } from "./Home";
import { About } from "./About";
But with current code I get an error:
Cannot read property 'prototype' of undefined
It seems that there is no window.{class}
Is it possible to do something like this in typescript?