quote:
Originally posted by CookieRevised
quote:
Originally posted by roflmao456
@cookie: that enumeration for status code you posted returns undefined if like variable[MyStatus]. using it like variable.STATUS_ONLINE will work, however.
blame matty, he posted it, not me 
Ah yes, you can't use the value of a variable or expression as identifier for a property when you're defining an object literal. "STATUS_ONLINE" is interpreted as a string identifier for the property, it does not take the value of STATUS_ONLINE to use as identifier.
Here are some example snippets, for those interested in what went wrong here:
js code:
var key = "123";
var obj = {
key : "abc"
};
// obj.key or obj["key"] equals "abc"
// obj[key] is undefined
var obj = {
"key" : "abc"
};
// same object as above
var i = 0;
var obj = {
(i++) : "first",
(i++) : "second"
};
// gives a syntax error
// property identifier must be a constant number or string
var i = 0;
var obj = {};
obj[i++] = "first";
obj[i++] = "second";
// this will work though, the square brackets can take both constant or variable values