javascript - Dynamically reference an import -
in ecmascript 6, how can instantiate class imported module variable?
ex: import mymodule './modules/modulename'; let myvar = "mymodule"; let foo = new window[myvar]( params );
you have create mapping containing imported modules want dynamically instantiate. e.g.
var classes = { mymodule, };
then can do
new classes[myvar]();
Comments
Post a Comment