I've been testing this in the browser console of FireFox, not sure if other javascript environments have this:
◄ {x:function(){console.log("test");}}["x"]();
► SyntaxError: function statement requires a name
Why? This works though:
◄ ({x:function(){console.log("test");}})["x"]();
► undefined
► "test"
(In case anyone is wondering: I really hate the switch,case,break syntax. I'd rather use this construction.)
The brackets in the first one is resulting in a block statement.
The first one looks like this when the semicolons are injected
{
x : function() {
console.log("test");
}
};
["x"]();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With