js es6 数组解构赋值

捕获剩余项

var [head, ...tail] = [1, 2, 3, 4];
console.log(tail);
// [2, 3, 4]

在生成器的作用

function* fibs() {
  var a = 0;
  var b = 1;
  while (true) {
    yield a;
    [a, b] = [b, a + b];
  }
}

var [first, second, third, fourth, fifth, sixth] = fibs();
console.log(sixth);

你可能感兴趣的:(js es6 数组解构赋值)