我想知道是否有可能简化这段代码并将其写成一行(我甚至可以使用ES6-7)
const { dimensions } = this.state
const { height} = dimensions
console.log(height)发布于 2018-01-24 22:45:59
你可以使用destructure a nested structure。
解构内部属性-高度:
const state = { dimensions: { width: 200, height: 100 }}
const { dimensions: { height } } = state
console.log(height)
分解外部和内部属性-尺寸和高度:
const state = { dimensions: { width: 200, height: 100 }}
const { dimensions, dimensions: { height } } = state
console.log(dimensions)
console.log(height)
https://stackoverflow.com/questions/48425187
复制相似问题