class HelloWorldComponent extends React.Component {
constructor() {
super()
this.getInput = this.getInput.bind(this)
}
getInput() {
alert('focused');
}
render() {
return (
<input type="text" onFocus={getInput}/>
);
}
}
ReactDOM.render(
<HelloWorldComponent/>,
document.getElementById('react_example')
);
このコードで何が問題になっていますか?警告を発することができない、私はgetInputが定義されていないエラーを持っている。反応入力要素の "ReferenceError:getInputが定義されていません"
http://jsbin.com/qoduyawaci/1/edit
'this.getInput = this.getInput.bind(この)' - なぜですか? –
@ジャロマンダXなぜか? –
私は間違っているかもしれませんが、 'this.getInput'はすでに' this'のプロパティであるため 'this'にバインドする必要はないと思っていたでしょう...私は私は99%が「これ」の仕組みを確信しているとしか言えませんが、ちょうど私に奇数(冗長)コードのように見えます –