Strict mode recap

Lars Hansen lhansen at adobe.com
Wed Apr 2 20:15:32 PDT 2008


> -----Original Message-----
> From: zeppieri at gmail.com [mailto:zeppieri at gmail.com] On 
> Behalf Of Jon Zeppieri
> Sent: 2. april 2008 20:51
> To: Lars Hansen
> Cc: es4-discuss at mozilla.org
> Subject: Re: Strict mode recap
> 
> On 4/2/08, Lars Hansen <lhansen at adobe.com> wrote:
> >  >
> >  > I meant something like:
> >  >
> >  > var foo::[bar] = baz;
> >  >
> >  > My objection to expr::[expr] in earlier messages was based on  > 
> > the assumption that these computed names could be used on the  > 
> > left-hand side of an assignment expression -- which, I'm  > pretty 
> > sure, is syntactically valid.
> >
> >
> > But that by itself can't introduce bindings (except global ones).
> 
> I didn't know that, but I'm happy to hear it.  I figured, 
> from the syntactic form alone, that:
> 
> var foo::[bar] = ...
> 
> ... would introduce a function-local binding (if the name 
> wasn't already bound) -- since that's what var normally does.

That form is not allowed, to my knowledge.  If the grammar allows it
then this could be (a) a bug or (b) missing semantic constraints.

> > If you want to introduce a new binding then you have to do eg
> >
> >   ns var x = E
> >
> >  to introduce ns::x, and ns has to reference a namespace  
> definition, 
> > so it's not variable.  Nor is the x, obviously.
> 
> Good. But then why allow:
> 
> var expr::[expr] = ...
> 
> ... at all?

It's not.

> (I'm specifically referring to the fact that 'var'
> appears before the name.)

I understand that.

> This has the syntactic form of a 
> definition, but it can't actually be one, according to what 
> you've written.  It could only be an assignment.  (Okay, I 
> guess it could introduce a property on the global object, but 
> that's already a special case and doesn't require definition syntax.)

It should be illegal.

> >  But in that case:
> >
> >   var v1 = ns
> >   var v2 = "x"
> >   v1::[v2] = 20
> >
> >  updates ns::x, AFAIK.  Nothing you can't do with lexically  scoped 
> > eval.
> 
> That, by itself, isn't exactly an selling point; no one likes 
> lexically scoped eval.

I would say that "almost no one likes lexically scoped eval, almost 
all of the time". :)  And the main reasons to dislike it are that
it can introduce bindings and that it is invisible (if implemented
like in Firefox, which is not required by ES3).

> I find computed names less objectionable now that I know 
> local bindings can't be introduced by them.  (I thought that 
> shadowing could occur, which wouldn't be detectable until 
> runtime.  Of course, that is true of 'with' -- but, again, 
> hardly a selling point.)  Can't say I'd be sorry if they were 
> removed from the language, though.
> 
> 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="http://www.opera.com/"><ns:q>Hi
there</ns:q></ns:p>
  var ns = new Namespace("http://www.opera.com/");
  var em = "q"
  document.writeln(x.ns::[em]);
  </script>

--lars



More information about the Es4-discuss mailing list