ReactJS - 如何通过逗号后的参数设置 属性?

ReactJS - How a property can be setted by an argument following a comma?

我目前在 ReactJS 文档的特定部分工作 - 这里是相应的 link : 在 https://reactjs.org/docs/lifting-state-up.html or on codepen : https://codepen.io/gaearon/pen/WZpxpz?editors=0010#0 中。

代码中有些东西在审问我: 一个值怎么可能被一个在逗号后的函数中传递的参数更新。这里的例子更容易理解:

 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'};
  }

温度参数如何处理温度设置属性,如果有人能给我解释一下就好了。

亲切的问候, J.Doe

这个:

  handleCelsiusChange(temperature) {
    this.setState({scale: 'c', temperature});
  }

等同于:(注意 temperature 属性)

 handleCelsiusChange(temperature) {
    this.setState({
        scale: 'c', 
        temperature: temperature
    });
  }

相当于:

 handleCelsiusChange(newValue) {
    this.setState({
        scale: 'c', 
        temperature: newValue
    });
  }

第一个语法是ES6中引入的new shorthand form