Proposal: opt-out local scoping

Erik Arvidsson erik.arvidsson at gmail.com
Thu Aug 28 14:12:21 PDT 2008


On Thu, Aug 28, 2008 at 12:29, Dave Herman <dherman at ccs.neu.edu> wrote:

>> Would that really satisfy Erik's use case? He seemed to think that
>> doing, at the top level --
>>
>>  var global = this;
>>
>>  function foo() {
>>    global.bar = 3;
>>  }
>>
>> is vulnerable to some ${person} going --
>>
>>  function foo() {
>>    var global = /* something else */
>>    global.bar = 3; /* now not the *real* global; system fails! */
>>  }
>
> You can make the same case for any variable. This is just lexical scope in
> action. The meaning of a variable reference is its innermost lexical
> binding. If you shadow a variable, it's shadowed.
>
> Erik, was this your concern?

I'm not concerned about someone shadowing it.  My concern was with
cases like the one Brendan pointed out as well as code snippets like:

new function() {
  var global = this;
  global.print(124);
}

Some people tend to use that format over (function() { })() and
wrapping code with that construct would break the global reference.

-- 
erik


More information about the Es-discuss mailing list