ES6深度嵌套对象解构

我有一个名为 this.props的对象,其中包含

{
actions: Object,
dirty: false,
form: "Statement",
autofill: function(),
**statement: Object**
}

statement包含

{
firstName: "John"
lastName: "Peter"
isConfirmed: true
}

我想在同一行中使用 es6解构提取 statement对象和 isConfirmed属性

我试过了

const { statement: isConfirmed, isAdmin } = this.props

当我做 let a = isConfirmed, b = statement的时候,我会得到一个错误

36329 次浏览

I would like to extract statement object and the isConfirmed property in the same line

const { statement: { isConfirmed }, statement } = this.props;

That way you get both isConfirmed and the whole statement object.

References: