JavaScript 2.0
Core Language
Namespaces
|
Wednesday, September 4, 2002
A namespace
definition defines a new namespace named Identifier.
A namespace
definition may only be located at a scope that allows
class definitions. If a namespace is defined as a member of a class, then the namespace must be declared static
.
A use namespace
directive makes the contents of each namespace in the comma-separated list ParenListExpression
accessible without a qualifier.
use namespace
directives are lexically scoped and their effect does not extend past the end of the enclosing
block, directive group, or substatement group. A use namespace
directive may be preceded by attributes; however, all such attributes must evaluate
to either true
or false
.
The following paragraphs describe what happens when a name is looked up. See also the description of how namespace attributes affect name definitions.
Conceptually, an instance x is a collection of properties.
All properties have property names q::
nC,
where q is a namespace, n is an identifier, and C is a class. There may be several aliases
that refer to the same property (due to either multiple namespace attributes
or aliases introduced with the export
definition), but a property name q::
nC
can refer to at most one property of an instance.
An instance x can have several properties q::
nC with
the same namespace q and name n but different classes C. In the following descriptions, q::
n
denotes the most derived of these properties, which is the one with the most derived class C.
A property reference can be either unqualified or qualified and is looked up according to the table below. There are two
entries in the table for each kind of lookup, depending on whether the left operand of the .
operator is a SuperExpression
or not. x is an expression that evaluates to an instance,
is the set of all scopes enclosing the property reference, and Q is the set of
all namespaces q that are use
d by the scopes in .
Qualified reference x. q:: n where q
is a namespace |
Select x’s most derived property q:: n. Signal an error if there
is no such property. |
Qualified reference super x. q:: n
where q is a namespace |
This form may only be used for references in the scope of a class C other than Object .
Let S be C’s superclass. Among all of x’s properties q:: nA
select the one whose class A is most derived but still either S or an ancestor of S.
Signal an error if there is no such property. |
Unqualified reference x. n |
Let A be the least derived (closest to Object ) class such that x contains
at least one property named q:: nA where q is any
element of Q; signal an error if x has no such properties. Let Q' be the set of all namespaces
q such that q is in Q and x contains the property named q:: nA.
Let P be the set of all most derived properties q:: n of x such
that q is in Q'. If P has only one element p or if all of P’s elements
are aliases of one property p, select p; otherwise signal an error. |
Unqualified reference super x. n |
This form may only be used for references in the scope of a class C other than Object .
Let S be C’s superclass. Let A be the least derived (closest to Object )
class such that x contains at least one property named q:: nA
where q is any element of Q; signal an error if x has no such properties or if A
is not S or an ancestor of S. Let Q' be the set of all namespaces q such that
q is in Q and x contains the property named q:: nA.
For each q in Q' let Bq be the most derived class such that Bq
is S or an ancestor of S and x contains the property q:: nBq;
for each q in Q' let pq be the property q:: nBq.
Let P be the set of all such properties pq. If P has only one
element p or if all of P’s elements are aliases of one property p, select p;
otherwise signal an error. |
Dynamic reference x[ s] |
Let s evaluate to a string n. Get the property x.public:: n.
Signal an error if there is no such property. |
Dynamic reference super x[ s] |
Let s evaluate to a string n. Get the property super x.public:: n.
Signal an error if there is no such property. |
Note that the only way to access an overridden method is to use super
. This is by design
to prevent security attacks.
Conceptually, all variables (which for the purpose of this section also include constants, functions, classes, and such)
have qualified names q::
n, where q
is a namespace and n an identifier. There may be several aliases that refer to the same variable (due to either
multiple namespace attributes or aliases introduced with the export
definition), but there cannot be two different variables defined using the same qualified name in the same scope.
A variable reference can be either unqualified or qualified and is looked up as follows:
Qualified reference q:: n where q is a namespace |
Let be the set of all scopes
enclosing the qualified reference q
|
Unqualified reference n |
Let be the set of all scopes enclosing the unqualified reference n. Search the scopes in , starting from the innermost one and continuing outwards until a value is found or all scopes have been examined. If no binding has been found after all scopes have been examined, signal an error. For each scope S in , do the following:
|
Waldemar Horwat Last modified Wednesday, September 4, 2002 |