Proposal: opt-out local scoping

ihab.awad at gmail.com ihab.awad at gmail.com
Thu Aug 28 12:20:50 PDT 2008


On Thu, Aug 28, 2008 at 12:14 PM, Dave Herman <dherman at ccs.neu.edu> wrote:
>> For what value of "global" should the "global" keyword be global? };->
>
> I interpreted Erik's point to be that the binding of `this' is not lexically
> scoped, so it would be useful to have a lexically scoped variable initially
> bound to the global object. IOW, if I write:
>
>    global.print("blah blah blah")
>
> and the same refactoring:
>
>    (function() {
>         global.print("blah blah blah")
>    })()
>
> continues to work the same.

Cool. Would there be a 'global' for each module (for some
interpretation of "module" but assuming each module has its own
separate top-level lexical scope, as appears to be the growing
concensus)?

> But there's no need for a special keyword or anything like that.

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! */
  }

?

Ihab

-- 
Ihab A.B. Awad, Palo Alto, CA


More information about the Es-discuss mailing list