How to create an object in JS with an unknown name?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
45 views
Hi.

Listen, and can somehow in JS to create an object from class C is not known in advance name?
I mean, something like this:

let name = 'someName'; let obj = new name();


That is to say that JS didn't have a name class(), and took the name from a variable name?

In PHP it is simple — there's just going to string and passed parameter. And in JS it possible?
by | 45 views

1 Answer

0 like 0 dislike
window.someName = function() {return {test: function(){}, asdasd:123}}; let name = 'someName'; let obj = new window[name](); console.log(obj, obj.asdasd);
by

Related questions

0 like 0 dislike
3 answers
0 like 0 dislike
1 answer
asked May 1, 2019 by miklpikl
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
asked Mar 25, 2019 by kirsan_vlz
110,608 questions
257,187 answers
0 comments
40,796 users