Greetings,
I have been working on a custom namespace in appcelerator but have run into a problem updating global namespace variables from within certain Titanium objects.
I have a wrapper called "myObj", and inside of myObj is another object called "globals" which contains variables that are set and used throughout the namespace.
myObj.globals = {
userBalance: null,
userAuthenticated: false,
deviceGeoActive: false
}
So I've created a custom wrapper for the geolocation module and inside of that wrapper is the standard Ti.Geolocation.getCurrentPosition(e) function and some custom stuff to be used with the app.
Inside of the Ti.Geolocation.getCurrent...(e) I check to see if location service is available on the device and has been authorized for the app. Then I want to update the deviceGeoActive o开发者_开发知识库bject property in myObj.
Ti.Geolocation.getCurrent...(e){
if (e.success){
myObj.globals.deviceGeoActive = true
}
}
This way I'll be able to check if the device is Geo enabled anywhere, anytime.
Why I believe it's failing (and this is a guess, I'm fairly new at javascipt) is because Ti is outside of the myObj namespace and therefore cant access it in this way.
Can anybody point me in the proper direction?
Thanks,
Josey
Thanks @Khez for helping get me to this point!
The only solution I can think of is to do window.myObj in both cases to ensure proper scope. Let me know of the outcome of this - @khez
Titanium Appcelerator doesn't work inside of the window namespace but your suggestion did make me think to add myObj to the global Ti (or Titanium) namespace.
So in the beginning I had this:
var myObj = {}
But myObj was being ignored by Ti.
To add it to the global Titanium namespace I modified it like so:
Ti.myObj = {}
myObj = Ti.myObj;
This way any calls to myObj remain don't have to be changed to reference Ti.
This means that myObj is now a child of the parent (global) Ti namespace.
Thanks again Khez
精彩评论