【发布时间】:2019-10-29 13:52:55
【问题描述】:
有人能描述一下将 [this.props.currency] 放在返回对象之后的目的吗,或者我可以在哪里了解这种模式,因为我以前没见过。
我不是在问 this.props.currency 是什么,而是在返回对象之后的目的。
在这篇博文中看到: https://javascriptplayground.com/react-extracting-logic/
export const getCurrencyData = currency => {
return {
GBP: { base: 100, symbol: '£' },
USD: { base: 100, symbol: '$' },
}[this.props.currency];
};
【问题讨论】:
-
它只是对对象进行索引。大概
this.props.currency将包含GBP或USD并返回相应的元素。尚不清楚该函数为何采用currency参数。 -
谢谢。我认为文章提到货币参数是一个错误。我现在看到这只是括号表示法。我只是通常不会这样看。
标签: javascript arrays reactjs object ecmascript-6