ES6是否支持{a as a1} = obj这样的扩展语法,或者是否存在RFC?

时间:2018-02-16 08:34:52

标签: javascript ecmascript-6

请考虑以下代码段

const x = {
     name: 'somebody'
};

const { name as somePerson } = x;  // Would be awesome to have something like this

1 个答案:

答案 0 :(得分:3)

您可以更改Object Property Assignment Pattern [You Don't Know JS: ES6 & Beyond, Chapter 2: Syntax]中的目标:

  

此处的句法模式为source: target(或value: variable-alias)。

{ name: somePerson }

const x = {
     name: 'somebody'
};

const { name: somePerson } = x;

console.log(somePerson);