【发布时间】:2020-04-12 10:24:08
【问题描述】:
我正在尝试使用对象解构来提取变量,但这些变量已经存在,就像这样
const x=1, y=2 // Those should be 1 and 2
const {x,y} = complexPoint
const point = {x,y}
有没有办法在不重命名解构变量的情况下做到这一点?
一些喜欢这样的更新点避免const定义?
const point = {x,y} = complexPoint
预期的结果应该是使用对象解构
const x=1, y=2 // Those should be 1 and 2
const point = {
x:complexPoint.x,
y:complexPoint.y
}
【问题讨论】:
-
不确定你想在那里实现什么。您是否尝试通过解构提取然后创建对象?
-
是的,我正在尝试仅提取这些变量
-
复点的内容是什么?
-
它是一个像
{x,y,z,w,otherFunctions ....}这样的大复杂对象
标签: javascript ecmascript-6 destructuring object-destructuring