r/programming • • Dec 22 '11

The Problem with Implicit Scoping in CoffeeScript

http://lucumr.pocoo.org/2011/12/22/implicit-scoping-in-coffeescript/
83 Upvotes

116 comments sorted by

View all comments

Show parent comment

1

u/jashkenas Dec 23 '11

That's actually already taken care of. By default, there are no global variables in CoffeeScript -- every file is wrapped in an immediate invoked function, so variables declared at the top level are still local variables.

If you want to export global variables from a CoffeeScript file (which you probably do), you say window.globalObject = object in the browser, or use the exports object in Node.js.

1

u/notfancy Dec 23 '11

I mean an explicit import in a local scope of a name in the top-level scope. But it's not a good idea anyway, because the problem is with assignment, not with use of an up-level identifier.