Is there a way to instantiate a new object from a class based on a variable in ES6?
This is my scenario:
class SomeClass {
hasMany(what){
var instance = new window[what]();
var owned_objects = instance.allOwnedBy(this.constructor.name, self.id);
return instance;
}
}
However, this returns Uncaught TypeError: window.Group is not a constructor(…)
the hasMany is located within a Class. So what I want to achieve is that the function within this class, should instantiate another class based on the name of that class passed as a variable, and then return the instance.