Last active
November 7, 2015 16:36
-
-
Save KentaKomai/72285acac8b8049cfe40 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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