【问题标题】:object destructuring: how to use intermediate nested property对象解构:如何使用中间嵌套属性
【发布时间】:2016-01-13 07:14:49
【问题描述】:
var { iWantThis: { andThis, andThisToo } } = x;

有没有办法在一个解构调用中访问所有三个?我想避免这样的两个电话:

var { iWantThis } = x;
var { andThis, andThisToo } = iWantThis;

【问题讨论】:

标签: javascript ecmascript-6 destructuring


【解决方案1】:

我能想到的最接近的是:

var { iWantThis, iWantThis: { andThis, andThisToo } } = x;

虽然我会改用let,但如果我使用的是 ES6 ;)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-20
    • 2020-04-09
    • 2017-01-07
    相关资源
    最近更新 更多