Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/424.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 数组文字作为对象键?_Javascript_Arrays_Reference_Key - Fatal编程技术网

Javascript 数组文字作为对象键?

Javascript 数组文字作为对象键?,javascript,arrays,reference,key,Javascript,Arrays,Reference,Key,我很惊讶看到了一个挑战,因为我不知道这个语法是合法的。也就是说,看起来像这样的部分(我简化了一点): 对我来说,这看起来像是一个数组文本被用来访问一个对象键。这是JavaScript中记录的行为吗?对于记录,看起来数组的最后一个值就是被取消引用的值。它使用了For a表示字符串,基本上这会返回o,并在两者之间执行一些操作 部分: "eo" string [ bracket operator/stri

我很惊讶看到了一个挑战,因为我不知道这个语法是合法的。也就是说,看起来像这样的部分(我简化了一点):

对我来说,这看起来像是一个数组文本被用来访问一个对象键。这是JavaScript中记录的行为吗?对于记录,看起来数组的最后一个值就是被取消引用的值。

它使用了For a表示字符串,基本上这会返回
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'

本例中的方括号被解析为属性访问器,而不是数组文本。逗号被解析为a。其他部分并没有让我感到困惑,我唯一不知道的部分是属性访问器中逗号运算符的合法性。顺便说一下,该函数返回
未定义的
,而不是空对象。
g=()=>{}
将一个“空”函数分配给g,当调用该函数时,返回未定义的。如果没有函数体(或多个语句),则需要大括号
{}
来定义箭头函数的函数体;如果有零个或多个参数,则需要大括号
()
来定义参数。
"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'