[JavaScript] 展开运算符spread operator

展开运算符“...”(spread operator),用来展开iterable,不能用来展开iterator

可以用于三种情况:

(1)函数调用中

f(...iterable, 4, 5, 6)

例如:

function f(v, w, x, y, z) { }
var args = [0, 1];
f(-1, ...args, 2, ...[3]);

(2)数组字面量

[...iterable, 4, 5, 6]

例如:

var parts = ['shoulder', 'knees'];
var lyrics = ['head', ...parts, 'and', 'toes'];

(3)解构

例如:

[a, b, c, ...iterable] = [1, 2, 3, 4, 5, 6];    //“...iterable”必须放在末尾

你可能感兴趣的:([JavaScript] 展开运算符spread operator)