Extending your app over multiple files
So far all of the code has been contained in a single app.js
file. However, this soon becomes cluttered, unstructured, messy, and unmanageable. No language worth its salt expects you to write the full application in a single file. Titanium is no exception and exposes several methods to manage your code over several files.
The simplest and most basic method is Ti.include
.
Titanium.include
Titanium.include
allows you to attach source code from another file. It is analogous to #include
in C, xsd:include
in XML, and similar to import
in Java. It allows you to break your code out into files of a manageable size.
Tip
While Ti.include
makes it easy to split your code over files, it is not the preferred method. Using commons and the require keyword shown later in the chapter should be used where possible.