Is it possible to name a object property directly inside the object declaration itself, insted of doing it afterwards?
For examle, this works:
var name  = "foo";
var obj   = {};
obj[name] = "bar; // obj.foo === "bar"
But is there a way to do it somehow inside the object itself, like:
var name  = "foo";
var obj   = {
    name: "bar" // obj.name === "bar"
};
I know it is possible to use strings for property names, so I was thinking something like this should do as workaround, but it didn't:
var obj   = {
    "" + name: "bar"
};
Is there a way to do this?
 
    