对象解构:如何使用中间嵌套属性 [英] object destructuring: how to use intermediate nested property

查看:72
本文介绍了对象解构:如何使用中间嵌套属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

是否有一种方法可以在一次解构调用中访问所有这三个对象?我想避免像这样的两个电话:

Is there a way to get access to all three in one destructuring call? I want to avoid two calls like so:

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

推荐答案

我能想到的最接近的是:

The closest I can come up with is:

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

如果我使用的是ES6,应该使用let代替;)

Thought I'd use let instead, if I'm using ES6 ;)

这篇关于对象解构:如何使用中间嵌套属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆