Strict mode recap

Lars Hansen lhansen at
Thu Apr 3 12:52:08 PDT 2008


> -----Original Message-----
> From: zeppieri at [mailto:zeppieri at] On 
> Behalf Of Jon Zeppieri
> Sent: 3. april 2008 10:10
> To: Lars Hansen
> Cc: es4-discuss at
> Subject: Re: Strict mode recap
> On Wed, Apr 2, 2008 at 11:15 PM, Lars Hansen 
> <lhansen at> wrote:
> >  >
> >  > Is this already in AS3?  If so, is it often used?
> >
> >  The syntax comes from E4X, which is incorporated into AS3 and  
> > Spidermonkey.  Try this in Firefox:
> >
> >   <script type="text/javascript;e4x=1">
> >   var x = <ns:p xmlns:ns=""><ns:q>Hi
> >  there</ns:q></ns:p>
> >   var ns = new Namespace("");
> >   var em = "q"
> >   document.writeln(x.ns::[em]);
> >   </script>
> I'm aware of E4X.  I meant: is it possible to refer to 
> lexical bindings in this manner in AS3?

Yes.  AS3 has an annoying restriction on where 
user-defined namespaces may be used, but the 
following example captures it without using E4X:

  package X {
    namespace myns;

    class C {
        myns var v = 37;

    var x = myns;
    var y = "v";

    print((new C).x::[y]);

This does print '37' if compiled with ASC and run through 
the Tamarin VM.

> I guess I don't see what use case is satisfied by this 
> feature that isn't already met by the existence of Map.  
> After all, the effect of this feature is to turn lexical 
> environments into (quasi) first class maps, with the peculiar 
> restriction that new name/value pairs cannot be added, though 
> existing ones can be mutated.  If a user actually needs that 
> functionality, it wouldn't be difficult to subclass Map to get it.
> And, yes, I know it's already possible to do this with 
> lexically scoped eval.  But why do you want to add another 
> way to do it?

Let me turn it around.

The syntax ns::v is in the language, for constant identifier v.
If E4X is implemented in an implementation (as it will be in 
ActionScript and presumably in Firefox, at least), so is 
ns::[expr].  How would a restriction to require ns to be a 
compile-time constant (in either form) and not a run-time 
value, or a restriction to disallow the latter form in ES4
but not in E4X, benefit ES4?


More information about the Es4-discuss mailing list