Skip to content

Instantly share code, notes, and snippets.

@KentaKomai
Last active November 7, 2015 16:36
Show Gist options
  • Save KentaKomai/72285acac8b8049cfe40 to your computer and use it in GitHub Desktop.
Save KentaKomai/72285acac8b8049cfe40 to your computer and use it in GitHub Desktop.
class Child extends React.Component {
// 子の関数
onChildChange(){
this.props.onParentChange()
}
}
class Parent extends React.Component {
//子に渡してる親の関数
//case 1
onParentChange(){
[非同期処理].then(
function(success){ this._hoge() }, // thisは[非同期処理]のインスタンス?
function(err) {}
)
}
//case 2
onParentChange(){
[非同期処理].then(
function(success){ this._hoge() }.bind(this), // thisは子
function(err) {}
)
}
//case 3
onParentChange(){
var self = this;
[非同期処理].then(
function(success){ this._hoge() }.bind(self), // thisは子
function(err) {}
)
}
//case 4
onParentChange(){
[非同期処理].then(
success => { this._hoge() }, // thisは子
function(err) {}
)
}
_hoge() { console.log('これを実行したい'); }
render() {
return (<Child onParentChange={this.onParentChange});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment