Strict mode recap
jaz at bu.edu
Wed Apr 2 19:50:41 PDT 2008
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.
> 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? (I'm specifically referring to the fact that 'var'
appears before the name.) 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.)
> 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 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?
More information about the Es4-discuss