【发布时间】:2019-09-09 11:00:16
【问题描述】:
我有这个代码
class BottomPanel extends React.Component<Props, {}> {
constructor(props) {
super(props);
this.dropDownUpdate = this.dropDownUpdate.bind(this);
}
dropDownUpdate = e => this.setState({ dropDownValue: e.currentTarget.textContent });
我想知道我是否可以重构
this.dropDownUpdate = this.dropDownUpdate.bind(this);
到
this.dropDownUpdate = this.dropDownUpdate;
如果是这样,为什么或为什么不呢?我只是在某处看到它正在这样做
this.dropDownUpdate = this.dropDownUpdate;
我不确定是否可以将其应用到我的代码中。
【问题讨论】:
-
你试过了吗?
-
是的,我认为到目前为止它正在工作。但是,除非我明白为什么,否则我真的不想使用它。
-
如果没有
this.dropDownUpdate = this.dropDownUpdate.bind(this);行,它的工作方式是否相同?
标签: reactjs