search

Home  >  Q&A  >  body text

javascript - JS extended statement usage

Why does directly entering ...a result in an error

曾经蜡笔没有小新曾经蜡笔没有小新2753 days ago598

reply all(2)I'll reply

  • 巴扎黑

    巴扎黑2017-06-28 09:29:08

    According to the es6 standard, it can only be used when passing parameters

    reply
    0
  • 滿天的星座

    滿天的星座2017-06-28 09:29:08

    It seems that the remainder/expand operator does not support this use. Currently, the scenarios where I have used the remainder/expand operator in practice include:

    // 函数形参
    function f(x,y,...z){};
    f(1,2,3,4,5); //f()内:z=[3,4,5]
    // 函数实参
    var a = [1,2,3];
    function f(w,x,y,z){};
    f(1,...a); //f(1,1,2,3)
    // 数组字面量
    var a = [1,2,3];
    var b = [...a,4]; //b=[1,2,3,4]

    So, the poster’s problem can only be output using onsole.log()

    reply
    0
  • Cancelreply