How can I instantiate a class by specifying a variable name? Consider this method inside the class:
animate: function(el, build) {
console.log(build.effect);
var animationClass = new build.effect(el,build);
},
An assembly is an object that contains a lot of material, but, most importantly, an “Effect”. This effect is the name of an independent animation class - one called "MarioKartMenu".
console.log (build.effect) displays "MarioKartMenu". But of course I get: TypeError: The result of the expression 'build.effect' [MarioKartMenu] is not a constructor.
If I destroy dynamism and just make the code as such:
animate: function(el, build) {
var animationClass = new MarioKartMenu(el,build);
},
It works great. Is it possible to make it dynamic, as I try to do?
source
share