Proposal: opt-out local scoping

Dave Herman dherman at ccs.neu.edu
Thu Aug 28 12:14:27 PDT 2008


> For what value of "global" should the "global" keyword be global? };->

I'm not sure if this is what Erik meant, but my intention was just that 
there's a variable bound in the standard library called `global' that's 
bound to the global object. The only reason I suggested the name 
`global' was that the spec uses the terminology "the global object." But 
there's nothing special about the variable; it can be shadowed like any 
other variable.

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:

     this.print("blah blah blah")

and then I refactor the code to say:

     (function() {
         this.print("blah blah blah")
     })()

it breaks. By contrast if I have a standard library binding `global' 
that's bound to the same thing as `this' at the top level, then I can write:

     global.print("blah blah blah")

and the same refactoring:

     (function() {
          global.print("blah blah blah")
     })()

continues to work the same. But there's no need for a special keyword or 
anything like that.

Dave


More information about the Es-discuss mailing list