Furthermore, Bob would like to share the script among many pages, so he'd like to have the entire script in a single BobUtilities.js file. Note that this problem would be newly introduced by JavaScript 2.0 if it were to evaluate type expressions at compile time. There exist other alternatives in between the dynamic execution model and the static model that also solve Bob's problem. One of them is described at the end of this chapter. In a pure dynamic execution model the entire program is processed in one pass.
Declarations take effect only when they are executed.
A declaration that is never executed is ignored. Scheme follows this model, as did early versions of Visual Basic. The dynamic execution model considerably simplifies the language and allows an interpreter to treat programs read from a file identically to programs typed in via an interactive console. One of the most significant advantages of the dynamic execution model is that it allows JavaScript 2.0 scripts to turn parts of themselves on and off based on dynamically obtained information. For example, a script or library could define additional functions and classes if it runs on an environment that supports CSS unit arithmetic while still working on environments that do not.