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

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

 

相关文章:

  • 2021-09-20
  • 2022-12-23
  • 2023-03-08
  • 2022-12-23
  • 1970-01-01
  • 2022-12-23
  • 2022-01-14
猜你喜欢
  • 2021-06-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-07
  • 2022-12-23
  • 2021-09-14
相关资源
相似解决方案