clarification on namespaces

Peter Hall peter.hall at memorphic.com
Mon Jun 11 05:50:49 PDT 2007


Ah ok. I was under the impression that you couldn't do:

if( condition ){
 namespace ns1 = "foo";
else{
 namespace ns1 = "bar";
}


And, in any case, if your URI came from an external source, you'd have
to use new Namespace() in order to use it.


Peter



On 6/11/07, Lars T Hansen <lth at acm.org> wrote:
> "namespace" is not a pragma, it just creates a new namespace object
> with some identity.  You can pass these around as values:
>
>   namespace ns1, ns2;
>
>   var x = ns1;
>   new Name(x, "foo")
>
> you can't use namespace values in declarations, so "x var int y = 37"
> won't do, but IIRC you can use them in expressions, eg x::y.  From the
> reference implementation:
>
> >> namespace ns = "foo";
> >> ns
> [user-defined namespace foo]
> >> var v = ns
> >> v
> [user-defined namespace foo]
> >> ns var x = 10
> >> x
> [stack] []
> **ERROR** EvalError: uncaught exception: ReferenceError: unresolved
> lexical reference {multiname: [ns public '']::x } (near
> builtins/Error.es:83.47-83.47)
> >> ns::x
> 10
> >> v::x
> 10
>
> --lars
>
> On 6/11/07, Peter Hall <peter.hall at memorphic.com> wrote:
> > On 6/11/07, Lars T Hansen <lth at acm.org> wrote:
> > > Nit: The way I currently understand the spec the first argument to the
> > > Name constructor if called with two arguments must be a namespace
> > > value, not a string, but this introduces no particular problems:
> > >
> >
> > is it necessary to use the pragma? Surely you create a new
> > Namespace()... otherwise it does introduce a problem..
> >
> > Peter
> >
> _______________________________________________
> Es4-discuss mailing list
> Es4-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es4-discuss
>



More information about the Es4-discuss mailing list