Reputation: 20538
[INFO] iPhone Device family: iphone [INFO] iPhone SDK version: 5.0 [INFO] Projekt/1.0 (2.0.2.GA.2ff31a3)
I am building an iOS app in Appcelerator and in this app I want to create a CommonJS module for UI components that I add to the global variable and then use it in other commonJS modules.
My code is based upon this example:
http://developer.appcelerator.com/blog/2011/09/forging-titanium-episode-6-a-single-context-tabbed-application-template.html
I add it into app.js like this:
var globals = {};
globals.Components = require ('ui/Components');
I use it in other modules like this:
var button_right = new globals.Components.NavBarButton ();
Is this a good way of doing it?
Upvotes: 0
Views: 268
Reputation: 711
From the docs:
There shall not be ANY global variables in a Titanium application shared across all modules. Any data a module or any objects exposed by a module require should be passed in during construction or initialization.
So, you preferably pass any other parameter on new object's initialization, something like:
var module = new Module(param);
Upvotes: 1