Manipulating Object Context
Although the global window
object provides the outermost layer of context for a web application,
there may be times when you need to swap out the default context for
another one. For example, you may want to persist the exact state of a
session when the user exits an application, or you might have a custom
execution environment that's already been preconfigured for a
particular circumstance. Instead of having code that manually iterates
over sets of conditions to configure the environment each time, you
might opt to use Base's window facilities to swap out the existing
context for another one.
The following function allows you to change out the dojo.global object and dojo.doc at will. Note that while dojo.doc is simply a reference to the
window.document by default, it does
provide a uniform mechanism for identifying the context's current
document, which again can be quite useful for situations in which
managed object contexts are involved. dojo.body() is a shortcut for obtaining the
body of a document.
Warning
The body element is not
explicitly defined for a strict XHTML document and some other
documents you may encounter.
At a minimum, you should be aware of the following three functions from Base for manipulating context:
dojo.doc //Returns Document dojo.body( ) //Returns DomNode dojo.setContext(/*Object*/globalObject, /*Document*/globalDocument)
Finally, in the spirit of flexibility, Base also provides two functions that allow you to evaluate a function ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access