Strict mode recap

Lars Hansen lhansen at adobe.com
Fri Apr 11 14:42:32 PDT 2008


> -----Original Message-----
> From: Brendan Eich [mailto:brendan at mozilla.org] 
>
> >  I think you're trying to say something else too but I can't figure

> > out what it is, something about the ns in ns::id being a literal in

> > a stronger sense than what I just outlined?
> 
> Let me try to be clearer. In ES3,
> 
> obj = {prop: value}
> 
> is sugar for
> 
> $tmp = new Object  // fixed in ES4 to not evaluate 'new Object'
>                     // but instead use memoized Object type
> $tmp.prop = value  // evaluate value only, not prop the literal id
> obj = $tmp
> 
> All I am noting is that
> 
> obj = {ns::prop: value}
> 
> might want to involve no further evaluation of arbitrary expressions  
> than the ES3 case.

The problem is that 'ns' does not have a fixed meaning,
it can't, because namespaces can themselves be defined
in namespaces.

Consider 

  namespace NS1; use namespace NS1
  namespace NS2; use namespace NS2

  NS1 namespace ns
  
  function f() {
    return { ns::prop: value }
  }

  NS2 namespace ns

Rewriting the body of the function as

    let obj = new Object
    obj.ns::prop = value

it is plain (to me) that I should get an error (there are two 
competing definitions for ns) when f is called and IMO that
really indicates that there should be an error also in the
original code.

What you are saying is that you're objecting to the computation
(the lookup of ns) occuring even in the second case.  I agree
that that is far from desirable, for many reasons, but I 
have a hard time accepting that the introduction of NS2::ns
should not have an effect on that code when f is called
subsequently.

(I could make the same argument for types, obviously.)

I understand we can make special provisions for these cases
to avoid this problem, eg, when f is processed the first
time (whatever that means) ns is looked up and bound, and
subsequent introductions of bindings for ns have no effect.
This could be acceptable because namespaces are special
kinds of bindings, not mutable variables.  It's far from
pretty.  It requires definition before use, which is not
too bad for namespaces; though I suppose ns could be bound
when f is called the first time (sort of weird).

--lars



More information about the Es4-discuss mailing list