我一直在FireFox浏览器控制台中测试这个,不确定其他JavaScript环境是否也有此功能:
◄ {x:function(){console.log("test");}}["x"]();
► SyntaxError: function statement requires a name
为什么?这个虽然能正常工作,但为什么呢:
◄ ({x:function(){console.log("test");}})["x"]();
► undefined
► "test"
(如果有人在想:我真的很讨厌 switch、case、break 语法。我宁愿使用这种结构。)
{x:1}
1(一个?!){x:1,y:2}
语法错误:意外的标记:“:”(啥?) - Stijn Sanders({x:1,y:2})
对象 {x: 1, y: 2}。 我猜这是一个语句<>表达式的问题。 - Stijn Sanders