Usage of rest parameter and spread operator in javascript

后端 未结 6 1888
时光取名叫无心
时光取名叫无心 2020-11-30 05:15

What\'s the usage of rest parameter that will be added in ECMAScript 6?

For example, in ECMAScript 5 you can do the following to get an array of parameters starting

6条回答
  •  孤城傲影
    2020-11-30 05:51

    I think the main differences in rest parameter are:

    • Arguments in ECMA5 arguments is like array not an array, so array normal methods is not available, but in ECMA6 arguments is an array.
    • I think building items array in ECMA5 code example will make the code a little slower because new array is instantiated.

提交回复
热议问题