0
foo = 'var'

basically coffeescript generates

(function(){var foo = 'bar';}).call(this);

But in the console I can't access the variable foo

console.log(foo);// error ReferenceError: Can't find variable: foo

How can I access the variable, and what's the point coffeescript do something like this?

mko
  • 21,334
  • 49
  • 130
  • 191

1 Answers1

1

This ensures that variables declared within that file don't accidentally leak into the global namespace. It forces the programmer to be more explicit about the variables that he chooses to expose.

If you'd like to expose foo do (exports ? this).foo = 'bar'.

Take a look at this question and answers for reference: How do I define global variables in CoffeeScript?

Community
  • 1
  • 1
Yuriy Nemtsov
  • 3,869
  • 4
  • 30
  • 44