我很惊讶地看到this answer挑战,因为我不知道这种语法是合法的。即,看起来像这样的部分(我稍微简化了一下):
"eo"[0,g=()=>{},g(),g(),1]
对我来说,这看起来像是一个数组文字被用来访问一个对象键。这是 JavaScript 中记录的行为吗?作为记录,数组的最后一个值似乎是被取消引用的值。
最佳答案
它使用 comma operator对于 access一个字符串,基本上这会返回 o
,并在两者之间做一些事情。
部分:
"eo" string
[ bracket operator/string accessor
0, value 0
g=()=>{}, generating an empty function
g(), call that function
g(), call that function again
1 take 1 as the last element of comma operator
] return 'o'
关于javascript - 数组文字作为对象键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36149383/