0

这里是 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;
4

1 回答 1

-3
    // new syntax
    const body = {
        ...args
    };
    // es5
    const body = Object.assign({}, args);
于 2017-10-31T16:11:45.203 回答