If I have a variable containing a string, is there a way that I can treat the contents of that string as the name of a type?
For example, is there a ???? in Javascript such that:
var ts = "Array";
var magic_type = ????; //magic
var obj_instance = new magic_type;
is valid and obj_instance == [] ?
You can instantiate it by using bracket notation with the global object.
jsFiddle.
If the constructor takes arguments, add them to the end.
As a side note, your code example…
…won’t ever evaluate to
truebecause the[]syntax will create a newArraywith a different memory location.