Recently I tried to build my project on droid and I'm receiving errors that my global var is undefined.
example: app.js
var APP = {}; Ti.include('lib/ui.js');inside my ui.js file I do this
(function(){ APP.ui = {} APP.ui.Somefunction = function()... })();
This used to work, but not sure why it's bombing any ideas? Working excellent in iPhone.
Any ideas would be appreciated.
thanks
1 Answer
There is a difference between global scope handling on iOS and android, but I thought it was limited to CommonJS modules and the require() call.
The difference is that on iOS, you can access variables in the global scpe from within a CommonJS module, but on android you can't. The bug is on the iOS side, since you should not be able to access globals from within CommonJS modules. As I understand it, that loophole should eventually be closed (and, as Esben points out, include() will eventually not be supported).
However, I'm surprised this issue would affect you with an include() call.
If cross-platform is important to you, and if you want your code to be maintainable over the long term, you should move your to a CommonJS structure and use require(). Use a technique like Esben presents to remove your dependence on globals.
Your Answer
Think you can help? Login to answer this question!