Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
250 views
in Technique[技术] by (71.8m points)

javascript - object destructuring: how to use intermediate nested property

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;
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The closest I can come up with is:

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...