我正在尝试分解对象,但是那些变量已经存在,像这样
const x,y
const {x,y} = complexPoint
const point = {x,y}
是否存在没有重命名解构变量的方法?像这样和更新点避免const
定义?
const point = {x,y} = complexPoint
您可以使用闭包将结构分解为现有变量:
const complexPoint = { x: 1, y: 2, z: 3 }
let x,y
({x,y} = complexPoint)
const point = {x,y}
console.log(point)