gpt4 book ai didi

javascript - 在 JavaScript 中分配给 { ... } 对象时这意味着什么?

转载 作者:行者123 更新时间:2023-12-03 04:51:27 25 4
gpt4 key购买 nike

我今天在学习 React 时遇到了这行代码:

import React, {Component, PropTypes } from 'react';

class App extends Component {

static propTypes = {
transactions: PropTypes.array,
summary: PropTypes.object,
gridFields: PropTypes.array,
actions: PropTypes.object
};
componentWillMount() {
const { transactions, actions } = this.props;
actions.requestSum(transactions);
}

render() {
const {
transactions,
gridFields,
summary,
actions
} = this.props;

return (
<div className="viewport">
<Header addTodo={actions.addTodo} />
<Grid fields={gridFields} data={transactions}>
<TransactionForm action={actions.addTransaction}/>
<TransactionSummary data={summary} fields={gridFields} />
</Grid>
</div>
);
}
}

}

但是 const {transactions, actions} = this.props 是什么?意思是?我已经习惯了这样的事情:

const myVariable = 3;

React 如何知道在事务和操作中存储什么内容?

最佳答案

这个解构语句

const {transactions, actions} = this.props;

含义类似于以下:

const transactions = this.props.transactions,
actions = this.props.actions;

要了解更多解构理解,请访问这里:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment

关于javascript - 在 JavaScript 中分配给 { ... } 对象时这意味着什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42638732/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com