ES6对象和数组解构

解构可以避免在对象赋值时再生成多余的中间变量:

function foo() {
  return [1,2,3];
}
let arr = foo(); // [1,2,3]

let [a, b, c] = foo();
console.log(a, b, c); // 1 2 3

function bar() {
  return {
    x: 4,
    y: 5,
    z: 6
  };
}
let {x: x, y: y, z: z} = bar();
console.log(x, y, z); // 4 5 6
原文地址:https://www.cnblogs.com/wujiaqi/p/7727857.html