Strict mode recap

Jon Zeppieri jaz at bu.edu
Thu Apr 10 20:03:23 PDT 2008


On 4/4/08, Lars Hansen <lhansen at adobe.com> wrote:
>
>  Classes can have namespaced properties and globals can too.  These
>  objects are in scope in a method (say), so in order to reference a
>  property in them from the method, at a minimum the form ns::id must be
>  available to the program (for constant ns and id).  But since ns can be
>  'public' such a name can (as far as I understand it know) also match a
>  local binding (parameter, let, var -- whatever), so this syntax is not
>  at present restricted to finding properties in true (non activation
>  record) objects.  I hope the forthcoming spec on names will clarify
>  this, so I suggest we hold off arguing about this particular point for
>  the moment.


On the compatibility namespace:  "There is currently no way to
explictly qualify a reference with noNS."  If that remains the case,
then all local variable references, other than those performed by
lexically scoped eval and those obscured by a with statement, can be
resolved ahead of time.  I think that would be a good thing.

The spec authors, however, are concerned by the fact that "code inside
of a WithStatement might want to refer to a local variable in an outer
scope without the possibility of being shadowed by a property on the
with object."  I'm ambivalent about this.  My initial reaction was to
wonder why any code that could be affected by shadowing in this way
would ever be in a with statement.  Then I realized that most code in
actual with statements probably could be affected by this, and the
proposal was really meant as a partial bug fix for with statements.

So, here are my thoughts:

- Taking advantage of the ability to avoid evil with-shadowing in this
manner requires users to qualify the appropriate names explicitly.
The time spent doing that would be better spent turning the with
statement into a block with a let definition and explicit object
property references.  (Actually, let statements would be the best
replacements for with statements.  Too bad they were removed.)  On the
other hand, references inside a with statement are presumably (this is
not based on any evidence) more likely to refer to with-object
properties than not, so there may be significantly fewer local
variable references to qualify.

- The suggested fix depends upon the (unwritten) stricture that
definitions cannot explicitly be qualified with noNS.  Otherwise,
given the example from the spec:

    function f (o) {
        var count = 10
        with (o) {
            for (var i = null::count; i > 0; --i) {
                ...
            }
        }
    }

    var o = { null var count = 100, ... };
    f(o);

... would make f do the wrong thing.  This asymmetry (explicit
reference but no explicit definition) is a minor inelegance.  (Though
maybe it's true of some other namespaces, as well?)

- Brendan's reformed with statement addresses the same problem without
treating local binding environments as presumptive first class
objects.  No surprise, I prefer a specific fix to a specific problem,
rather than adding what amounts to a restricted use of lexically
scoped eval as a general language feature.

-Jon



More information about the Es4-discuss mailing list