Reputation: 6292
I am new to titanium mobile and I am a bit stuck. I have an app.js file and services.js file which sends some HTTP requests to an URI my issue is I want to create a global variable within the app.js which the services.js can use and other files as and when they get included.
What is the best way to do this ?
In PHP you would have a config file but how do you do in titanium mobile ?
Upvotes: 0
Views: 743
Reputation: 24815
You could do it 3 ways, depending on how long you'll need the variable. If it is needed outside of the session scope (so later on) you could store it either in an Property or SQLite Database
The last option, which is a session-only option is a regular JavaScript variable. Like Jeff has pointed out (copying his code here)
var myapp = {};
myapp.myGlobalVariable = 'something';
Declaring this myapp
should be done before any function opens. So in the global scope.
Upvotes: 1
Reputation: 1130
If you are using services.js from a Ti.include, it will have access to everything declared in app.js. You usually create your own namespace and put 'global' variables in that:
var myapp = {};
myapp.myGlobalVariable = 'something';
Here is a more complete example from Aaron Saunders.
Upvotes: 1