I have a question which shouldn't be to difficult, but I've been spending days and can't seem to find the answer. All the solutions I found didn't help me, they all threw errors.
I made a Class in Javascript and want to create a new instance dynamically, so that I can instantiate multiple classes depending on the parameter in a function. It doesn't seem te work, and I wonder why.
settings.js and main.js are loaded via <script>
tag in the HTML file, with settings.js being loaded first.
main.js
let myClass = new settings(); // Works
let myClass2 = test('settings'); // Error: Uncaught TypeError: param is not a constructor
function test(param){
return new param();
}
settings.js
class settings{
constructor(){
console.log("works");
}
}
Thanks for any help!