在React Native中使用简单的Mobx Store,并试图弄清楚为什么我无法使用它。我有一个函数,我想调用另一个函数来inatlize数据库监听器
它非常简单
class Store {
@action FirstFunction(){
this.SecondFunction();
// I also tried:
SecondFunction();
//neither worked
}
@action SecondFunction(){
console.log("Second Function!");
}
}
有任何想法吗?在mobx中这可能吗?无法弄清楚为什么它不会..
使用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);