Skip to content

Instantly share code, notes, and snippets.

@cubdesign
Last active August 29, 2015 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cubdesign/70c6526e8583f8d26e3a to your computer and use it in GitHub Desktop.
Save cubdesign/70c6526e8583f8d26e3a to your computer and use it in GitHub Desktop.
Reactをes6で使う場合のbindの問題 ref: http://qiita.com/cubdesign/items/ee8bff7073ebe1979936
save(e){
this.props // undefined になる
}
render (){
return (
<button onClick={this.save} />保存</button>
);
}
save = function (e){
this.props // undefined ではない
}
render = function (){
return (
<button onClick={this.save} />保存</button>
);
}
constructor() {
super();
this.save = this.save.bind(this);
}
render = function (){
return (
<button onClick={this.save} />保存</button>
);
}
render = function (){
return (
<button onClick={this.save.bind(this)} />保存</button>
);
}
render = function (){
return (
<button onClick={(event) => this.save(event)} />保存</button>
);
}
render = function (){
return (
<button onClick={::this.save} />保存</button>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment