Draft 3 of the Namespace spec. This introduces the ability to construct namespaces at run-time without having to resort to eval, and with it comes the ability to pick the namespace name out of the Namespace object and also to call the Namespace class as a function in the style of all the other classes.
--larsTitle: The class "Namespace"
The class Namespace
NAME: "The class 'Namespace'" FILE: spec/library/Namespace.html CATEGORY: Pre-defined classes SOURCES: REFERENCES [1], [2] SPEC AUTHOR: Lars DRAFT STATUS: DRAFT 3 - 2008-03-20 REVIEWED AGAINST ES3: N/A REVIEWED AGAINST ERRATA: N/A REVIEWED AGAINST BASE DOC: YES REVIEWED AGAINST PROPOSALS: N/A REVIEWED AGAINST CODE: YES REVIEWED AGAINST TICKETS: YES IMPLEMENTATION STATUS: ES4 RI (partly) TEST CASE STATUS: ? CHANGES SINCE DRAFT 2 (2008-03-17) * There is a public constructor for Namespace objects * The 'Namespace' class object can be invoked as a function * There is a getter for a 'name' property on Namespace objects * The 'toString' method is tagged "override" * Presentation: More elaborate status block above CHANGES SINCE DRAFT 1 (2008-03-05) * Presentation: added an explicit "extends Object" clause * Namespaces are explicitly designated nullable and a null value is tied to the compatibility namespace noNS * The behavior of the 'toString' method has been tightly specified to allow Namespace objects to be compared predictably NOTES * "Forgeable" and "unforgeable" namespaces are discussed in the language spec. A forgeable namespace is created from a string, as with 'namespace f = "my namespace"'. An unforgeable namespace is created not from a string, as with 'namespace u' * The constructor and the 'name' getter are compatible with E4X REFERENCES [1] Section 4.2.10.4 of the base document: http://wiki.ecmascript.org/lib/exe/fetch.php?id=resources%3Aresources&cache=cache&media=resources:as3lang.doc [2] builtins/Namespace.es in the ES4 RI [3] Language definition, section on Names (forthcoming).
The class Namespace
is a final, non-dynamic, nullable,
direct subclass of Object
.
NOTE Namespace
values can be created by new
expressions in
the user program or by the evaluation of a namespace
definition,
which creates a new namespace and a constant binding for it.
COMPATIBILITY NOTE The Namespace
class is new in the 4th Edition of this
Standard.
Synopsis
The class Namespace
provides the following interface:
__ES4__ final class Namespace extends Object { public function Namespace(name=undefined) static meta function invoke(x) static public const length = 1 override intrinsic function toString(): string public function get name(): (string|undefined) }
The Namespace
prototype object provides the following direct
properties:
toString: function ()
Operators
The operators ==
and ===
compare forgeable Namespace
objects by comparing their names as obtained by the name
accessor,
see below. Forgeable namespaces with the same name are equal by those
operators.
In all other cases, Namespace
objects are equal only to
themselves.
Methods on the Namespace
class object
new Namespace(name= )
Returns
When the Namespace
constructor is called with no arguments
or with the argument undefined it returns a new unforgeable
Namespace
object. The returned object is unequal to every
previously existing Namespace
object.
When the Namespace
constructor is called with an argument
name that is not undefined it converts name to string and
returns a new forgeable namespace whose name is the converted value.
Implementation
public function Namespace(name=undefined)
Namespace(x)
Returns
The Namespace
class object called as a function returns a
Namespace
object. If x is a Namespace
object then it is
returned. Otherwise a new Namespace
object is constructed by
invoking the Namespace
constructor on x.
Implementation
static meta function invoke( x ): Namespace! { if (x is Namespace!) return x; return new Namespace(x); }
Methods on Namespace
instances
intrinsic::toString()
Description
The intrinsic toString
method converts the Namespace
object to a string. If the Namespace
object is forgeable (it was
created with an explicit name) then the string returned by
toString
contains the name as a substring.
Returns
The toString
method returns an implementation-defined
string.
Suppose the intrinsic toString
method is invoked on two
namespaces N1 and N2 yielding strings T1 and T2,
respectively. T1 and T2 are equal if and only if N1 is
equal to N2 (by ===
or ==
).
Suppose the intrinsic toString
method is invoked on two
different forgeable namespaces N1 and N2 created from strings
S1 and S2, yielding strings T1 and T2, respectively.
T1 and T2 have the same relationship (determined by the
relational operators) as S1 and S2.
Value Properties on Namespace
instances
name
Description
If this Namespace
object is a forgeable namespace then the
value of the property name
is the string name with which the
namespace was constructed.
If this Namespace
object is an unforgeable namespace then the
value of the property name
is undefined.
Methods on the Namespace
prototype object
Description
The methods on the Namespace
prototype object delegate to
their corresponding intrinsic methods.
Returns
The methods on the Namespace
prototype object return what
their corresponding intrinsic methods return.
Implementation
prototype function toString(this:Namespace) this.intrinsic::toString()
_______________________________________________ Es4-discuss mailing list Es4-discuss@mozilla.org https://mail.mozilla.org/listinfo/es4-discuss