Let's suppose that a library offers different classes (lib.Class1, lib.Class2, lib.Class3, ...). I have a variable "name" which stores the name of the class to be instantiated (Example: const name = "Class2").
How can I dynamically instantiate a class based on the variable? For example: const myClass = new lib.name(params); (I know this doesn't work).
I don't want to build any map myself because the library can change over time and offer different classes.
Can Reflect be any useful?
I know there is this question but it is creating a "map" which I'd like to avoid: Create an instance of a class in ES6 with a dynamic name?.