Javascript ReactJS-如何通过逗号后的参数设置属性?
我目前正在处理JS文档的一个特定部分-这里有相应的链接:在codepen:中或在codepen:上 密码里有一些东西在审问我: 一个值如何可能由在函数中传递的参数更新。下面是一个更容易理解的示例:Javascript ReactJS-如何通过逗号后的参数设置属性?,javascript,properties,callback,jsx,setstate,Javascript,Properties,Callback,Jsx,Setstate,我目前正在处理JS文档的一个特定部分-这里有相应的链接:在codepen:中或在codepen:上 密码里有一些东西在审问我: 一个值如何可能由在函数中传递的参数更新。下面是一个更容易理解的示例: handleCelsiusChange(temperature) { this.setState({scale: 'c', temperature}); } corresponding to : 哪个句柄: class Calculator extends React.Compone
handleCelsiusChange(temperature) {
this.setState({scale: 'c', temperature});
}
corresponding to :
哪个句柄:
class Calculator extends React.Component {
constructor(props) {
super(props);
this.handleCelsiusChange = this.handleCelsiusChange.bind(this);
this.handleFahrenheitChange = this.handleFahrenheitChange.bind(this);
this.state = {temperature: '', scale: 'c'};
}
温度参数如何处理温度属性的设置,如果有人能向我解释,那就太好了
亲切的问候,
美国能源部这:
handleCelsiusChange(temperature) {
this.setState({scale: 'c', temperature});
}
与此等效:(注意温度属性)
这相当于:
handleCelsiusChange(newValue) {
this.setState({
scale: 'c',
temperature: newValue
});
}
第一种语法是ES6中引入的好的,它是关于速记形式的。。。我现在好多了,谢谢你El Aoutar Hamza
handleCelsiusChange(newValue) {
this.setState({
scale: 'c',
temperature: newValue
});
}