There is a way to instantiate a class in JavaScript with a variable of type string , for example:
class User {
constructor() {
this._name = 'Luiz';
}
get name() {
return this._name;
}
}
const className = 'User';
const userInstance = new className();
// const userInstance = new User();
const name = userInstance.name;
console.log(name);
I would like the line:
const userInstance = new className();
It would have the same effect as:
const userInstance = new User();
Is it possible?