I came across this, issue where the following happens (in Chrome atleast), where I expect all of these expressions evaluating to ƒ alert() { [native code] } but some of them fail esoterically.
{
['a']: alert
}['a']
// Uncaught SyntaxError: Unexpected token ':'
({
['a']: alert
})['a']
// ƒ alert() { [native code] }
{
a: alert
}['a']
// ['a']
({
a: alert
})['a']
// ƒ alert() { [native code] }
{
a: alert
}.a
// Uncaught SyntaxError: Unexpected token '.'
({
a: alert
}).a
// ƒ alert() { [native code] }
As always, the compiler yields no diagnostics of what had possibly gone wrong. And I can't wrap my head around about what is going on behind scenes for this apparently counter-intuitive bizzare behaviour. At this point I can't differentiate between bugs and features of a JS engine. Explanations are highly appreciated!