Cannot read property 'globalData' of undefined;at App onLaunch function

Cannot read property 'globalData' of undefined;at App onLaunch function

最初是將 'globalData'  的定義放在了 app.js 最後面,認爲是還沒有加載;然後把定義放在 onLaunch 前面,但還是不行;所以認爲是在 App 的 onLaunch 事件處理程序中無法讀取globalData,因爲其還沒有被加載定義;

後來發現是 this 變量的作用域問題,在函數的一開始就定義一個變量指向this,

let that = this;

 

 

需要使用的時候調用這個新定義的變量就可以了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章