Titanium.include

Function of Titanium.
Platform Since
Android 0.1
iPhone 0.1
iPad 0.1
Mobile Web 1.8

Summary

Includes JavaScript code from one or more files.

Description

The include method has several interesting quirks:

  • The included JavaScript is interpreted in the current root execution context -- that is, either app.js or in the root context of a window opened with the url property. For example, in the following code snippet, the included code in some_module.js has access to globalVar, but not to the local variable, localVar:

    var globalVar = {};
    function loadModule() {
        var localVar = "A local value.";
        Ti.include('some_module.js');
    };
    loadModule();
  • The included filename is interpreted local to the current file. For example, suppose a.js includes dir/b.js. If b.js includes another file, c.js, this is interpreted as dir/c.js.

  • Calling include from an event handler does not work consistently across platforms.

  • Calling include on a non-existent file causes a runtime error. See also CommonJS Require.

Arguments

Name Type Summary
name String

Filename(s) to include.

Return Type

void