【发布时间】:2018-04-12 21:09:12
【问题描述】:
这里是 es6 的新手。有没有办法用 es6 特性缩短这段代码?我正在尝试从一个对象中解构并将这些拉取的属性放入一个新对象中。
const { Height, Width, Location, MapAttachmentTypes,
ZoomLevelAdjustment, CustomPushPins, CenterPushpinStyle, ScaleFactor } = args;
const body = {
Height,
Width,
Location,
MapAttachmentTypes,
ZoomLevelAdjustment,
CustomPushPins,
CenterPushpinStyle,
ScaleFactor
};
我试过了,但没用:
const body = { Height, Width, Location, MapAttachmentTypes, ZoomLevelAdjustment, CustomPushPins, CenterPushpinStyle, ScaleFactor } = args;
【问题讨论】:
-
我认为这已经被问过至少几次了;你彻底search了吗? (不是我的 dv)
-
“没用”是什么意思?
-
您的
args对象是什么样的?它会像你预期的那样解构吗? -
您是在尝试将属性作为新属性实际拉入
body或引用args的相关道具吗?
标签: javascript ecmascript-6 object-destruction