1.直接用bind呼叫
this.method.bind(this)
2.建構函式中用bind定義
class Foo{ constructor(){ this.method = this.method.bind(this); } }
3.用箭頭函式定義或呼叫
//定義 class Foo{ constructor(){ //定義1 this.method1 = () => { this.xxx = b; } } //定義2 method2: () => { this.xx = a; } } //呼叫 this.someThingAsync() .then(() => { this.method() })