2017-12-30 49 views
1

React Native의 간단한 Mobx Store로 작업하고 이것이 왜 작동하지 않는지 알아 내려고합니다. 나는 데이터베이스 리스너 Mobx의 다른 함수 내에서 함수 호출하기

는 아주 간단

class Store { 
@action FirstFunction(){ 
    this.SecondFunction(); 
    // I also tried: 
    SecondFunction(); 
    //neither worked 
} 

@action SecondFunction(){ 
    console.log("Second Function!"); 
} 

} 

어떤 아이디어

을 inatlize 다른 함수를 호출하고자하는 기능을 가지고? 이것이 mobx에서 가능한가? 이유가 무엇인지 알 수 없습니다.

답변

0

this을 사용하지만 this 값이 예상 한 값인지 확인해야합니다.

예 (JSBin)

class Store { 
@action firstFunction() { 
    console.log("First Function!") 
    this.secondFunction(); 
} 

@action secondFunction(){ 
    console.log("Second Function!"); 
} 
} 

const store = new Store(); 

console.log("This works:"); 
store.firstFunction(); 

console.log("This will throw an error:"); 
setTimeout(store.firstFunction, 1000);