Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

One of the bottlenecks of a Titanium application is JavaScript evaluation. This is particularly the case for Android, although the V8 runtime provides substantial improvements for this issue compared with Rhino. For that reason, to speed the startup and responsiveness of your application, you should avoid loading scripts until they are absolutely needed. As in the following application, which has three windows to be opened in succession on a click (touch) event, note that the dependent JavaScript for each window is not loaded until absolutely necessary.

...

On the downside, this pattern is less performant than CommonJS modules, especially on Rhino/Android. The rapid nature of this pattern can lead the developer to general, high-level bad practices and developer 'laziness'. Inheritance is vague or even non-existent. And critically, memory management can be difficult as object references can remain after they're no longer needed.

Code Block
linenumberstrue
languagejs
langjavascript
// create an object literal to be your app's namespace
var myapp = {};

// the following could be in a separate "ui.js" file and include()'d into your app.js
(function() {
	myapp.ui = {}; // this sub-namespace extends the app's namespace object

	myapp.ui.createApplicationWindow = function() {
		var win = Ti.UI.createWindow({
			backgroundColor:'white'
		});

		var header = Ti.UI.createLabel({
			text: 'My App Heading',
			top: 10
		});
		win.add(header);
		return win;
	};
})();

...