JavaScript Invocation Context

To use client-side JavaScript functions effectively you have to understand the way JavaScript partitions the client window into independent object spaces (via iframes), and the way common JavaScript framework code is made available to those spaces.

While this may be old hat for experienced browser-side JavaScript programmers, it is important to remember that every window or iframe contains an independent object space, with a separate space of global variables and objects. Adding, modifying, or deleting objects (or classes) in one iframe has no effect on any objects in other iframes. However, it is possible to refer to objects that "live" in a different iframe with variables in a different iframe. This is somewhat dangerous; if the iframe that instantiated the object (where its prototype lives) goes away (by being closed, or having its href modified) the object may no longer be able to carry out any operations. However, "value" objects such as strings or numbers may safely be shared across frames, even if the creating frame closes.

An iframe can have JavaScript code defined directly into its HTML page, or it can include JavaScript code that exists in a separate file. The latter technique allows the creation of standard "library" code that is available to many iframes, without the network or development overhead of copying the same functions into hundreds/thousands of files.

The subtle point to remember in the foregoing is that even though the same JavaScript file may be included in different iframes, each definition is completely independent of every other. If the included JavaScript defines a global, then every iframe gets its own separate global variable binding.

Since there are some commonly used objects, most iframes define and initialize global variables to reference these objects. The "main" object usually refers to the main iframe, containing cisMain.jsp. This iframe is never reloaded during a client session, and holds the central model object. The model itself is usually available as the "model" global in most iframes.