Hen*_*aye 4 javascript ecmascript-6
const question = this.props.question
const answer = question.answer
Run Code Online (Sandbox Code Playgroud)
重构以上代码片段以使用解构。
const { question } = this.props
const { answer } = question
Run Code Online (Sandbox Code Playgroud)
如何将这种破坏重构为一行?如果我这样做const { question : { answer } } = this.props,将不会得到参考question?
解构时,您可以多次引用同一属性:
const { question, question: { answer } } = this.props;
Run Code Online (Sandbox Code Playgroud)
const { question, question: { answer } } = this.props;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
50 次 |
| 最近记录: |