normally to create an object you would write:
function Dog(name) {
this.name = name;
}
fifi = new Dog("fifi");
How do I dynamically name the object so that I can write:
var name = "fifi";
[name] = new Dog(name);
to achieve the same outcome as:
fifi = new Dog("fifi");
If you know the object you’re creating the variable on (a property, not just a variable) you can use bracket notation, like this:
Later you could access it either way:
If it’s a global variable you’re after, that object (instead of
dogsabove) would just bewindow.