extracting namespace from a property

Jeff Dyer jodyer at adobe.com
Mon Feb 5 15:06:18 PST 2007


Brendan Eich wrote:

> Jeff proposes we call it Name.

Since in ES4 all names are qualified names, why burden the language with
a historical distinction that no longer exists?

Jd

> -----Original Message-----
> From: es4-discuss-admin at mozilla.org
[mailto:es4-discuss-admin at mozilla.org]
> On Behalf Of Brendan Eich
> Sent: Monday, February 05, 2007 2:33 PM
> To: Yuh-Ruey Chen
> Cc: es4-discuss at mozilla.org
> Subject: Re: extracting namespace from a property
> 
> You are right on top of this one. I've proposed a Name object (Jeff
> suggested not using E4X's QName class) to reflect qualified
> identifiers. This is necessary because what you propose is ambiguous
> with respect to existing objects having properties with "::" in their
> names (which has always been allowed; these would be accessed via []
> of course).
> 
> Here's the guts of the proposal:
> 
> Problem Statement
> 
> The for-in loop combined with namespace-qualified names means we need
> a Name class reflecting namespace-qualified identifiers of enumerable
> properties:
> 
> let o = {x:1, 2:"two", '@funny':3};
> for (let i in o)
>    print(i, typeof i);
> 
> Per ES1-3, and required for backward compatibility, this script
> should print
> 
> x string
> 2 string
> @funny string
> 
> Consider this code:
> 
> namespace n;
> let p = {n::m: 42};
> for (let i in p)
>    print(i, typeof i);
> 
> It would be impossible to index p.n::m by p[i] if i were "m" (if the
> output of this loop were m string). We need something like the QName
> class from E4X (ECMA-357). Jeff proposes we call it Name.
> Proposed Solution
> 
> The Name class is defined as follows:
> 
> class Name {
>    function Name(ns : Namespace, id : string)
>      : qualifier = ns
>      , identifier = id
>    {
>    }
> 
> 
>    intrinsic static function invoke(ns : Namespace, id : string) :
Name
>      new Name(ns, id);
> 
>    public const qualifier  : Namespace,
>                 identifier : string;
> }
> 
> An enumerating for-in loop or comprehension must reflect an
> enumerable property name as a Name instance if the property was
> defined with an explicit or default namespace other than public.
> Otherwise, with no or a public namespace, enumerating for-in reflects
> the name as a string per ES1-3 and existing JS implementations.
> 
> A property access of the form o[n] where n is of type Name looks for
> a binding in the namespace n.qualifier whose unqualified name is
> n.identifier.
> 
> ----
> 
> The only detailing that remains is what Name.prototype.toString
> should do. Current thinking is something like "[namespace public
> n]::m" for the example in the Problem Statement. Comments welcome.
> 
> /be
> _______________________________________________
> Es4-discuss mailing list
> Es4-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es4-discuss




More information about the Es4-discuss mailing list