【问题标题】:Does ES6 support spread syntax like { a as a1 } = obj or is there an RFC on that? [duplicate]ES6 是否支持像 { a as a1 } = obj 这样的扩展语法,或者是否有 RFC? [复制]
【发布时间】:2018-02-16 08:34:52
【问题描述】:

所以考虑下面的sn-p

const x = {
     name: 'somebody'
};

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

【问题讨论】:

  • 旁注:JavaScript 规范没有 RFC(据我所知)。有一个叫做 TC39 委员会的东西,它有一个标准流程来批准 ECMAScript 语言规范的提案。
  • 您应该始终首先参考 docs。他们通常对最常见的问题有解决方案。

标签: javascript ecmascript-6


【解决方案1】:

您可以更改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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-09
    • 1970-01-01
    • 1970-01-01
    • 2018-01-21
    • 1970-01-01
    • 1970-01-01
    • 2019-03-21
    • 2015-11-22
    相关资源
    最近更新 更多