0
class App extends React.Component {
method(){
console.log(this);
}
render(){
return (<div>
<button onClick={this.method}>Try it</button>
</div>)
}
}
ReactDOM.render(<App/>, document.getElementById('demo'));
私はあなたがそれを持っている(これを)this.method.bind使用する必要がなぜ?なぜ起こるのボタン要素オブジェクトがundefined
次のリアクションコードで、要素への参照が返されないのはなぜですか?
の代わりに返されている必要がありますので、ボタン要素は方法を駆動していると思います働いた?
は、[どのように「このhttp://blog.andrewray.me/react-es6-autobinding-and-createclass/ –
可能な複製を推奨読書します"関数内のキーワード作業?](http://stackoverflow.com/questions/133973/how-does-this-keyword-work-within-a-function) – aghidini