Scopes are associated with {@link com.google.gwt.dev.js.ast.JsFunction}s, but the two are not equivalent. Functions have scopes, but a scope does not necessarily have an associated Function. Examples of this include the {@link com.google.gwt.dev.js.ast.JsRootScope} and synthetic scopes thatmight be created by a client.
Scopes can have parents to provide constraints when allocating actual identifiers for names. Specifically, names in child scopes are chosen such that they do not conflict with names in their parent scopes. The ultimate parent is usually the global scope (see {@link com.google.gwt.dev.js.ast.JsProgram#getGlobalScope()}), but parentless scopes are useful for managing names that are always accessed with a qualifier and could therefore never be confused with the global scope hierarchy.
{@link JsScope} are used to define anonymous JavaScript functions. For example, let'stake the each
statement:
new JsQuery().$(".foo").each(new JsScope() { public void execute(JsScopeContext scopeContext) { scopeContext.self().chain("css", "border", "1px solid red"); } });
You can either pass arguments to the JsScope (like in JavaScript functions) (see constructor args).
@author Lionel Armanet @since 0.7 @see JsStatement @see JsScopeContext
|
|