desconsured es6导出有效的语法?

时间:2017-03-30 18:02:04

标签: javascript ecmascript-6

我想知道以下语法:

0

我无法在任何es2015 documentation中找到它,但它是supported by Babel's es2015 preset

这种语法是否真正标准化,正如babel似乎认为的那样?超出标准?

1 个答案:

答案 0 :(得分:3)

这里有几件事情。

export const { foo, bar } = {
  foo: 123,
  bar: 234,
};

相当于

const { foo, bar } = {
  foo: 123,
  bar: 234,
};

// Export all the names in the variable declaration.
export { foo as foo, bar as bar };

export可用于许多声明,并将导出该声明创建的任何变量。

如果您不了解解构,那么这将进一步简化,基本上是

const _tmp = {
  foo: 123,
  bar: 234,
};
const foo = _tmp.foo,
      bar = _tmp.bar;

// Export all the names in the variable declaration.
export { foo as foo, bar as bar };