I have a few strings
strings = [
"String",
"Object",
"Boolean"
]
and I would like to use them to declare new objects
for(var i = 0; i < strings.length; i++){
var x = new strings[i];
}
but instead I get this error:
TypeError: string is not a function
at Object.<anonymous> (/Users/path/code.js)
at Object.<anonymous> (/Users/path/code.js)
at Module._compile (module.js:456:26)
How can I treat strings as their underlying types?
Aside:
I know that I could do something like
type_map = {
String: String,
Object: Object,
Boolean: Boolean
}
and then go
for(var i = 0; i < strings.length; i++){
var x = new type_map[strings[i]];
}
which works, but I'm looking for something slightly more elegant if it exists.