0

I don't know if this is IDE related, or purely about the transpiling process. I use Webstorm on a mac, and have node,npm and coffeescript installed. The IDE is using that to make the transpiling to javascript:

//Coffeescript code, simple variable declaration
myamount = 56

//Traspiled javascript generated by CoffeeScript 1.6.3
(function() {
  var myamount;
  myamount = 5;
}).call(this);

Any clue why it puts the variable in anonymous function ? This is not correct transpiling.

Benj
  • 329
  • 1
  • 4
  • 11
  • Similar question here: http://stackoverflow.com/questions/4214731/coffeescript-global-variables – jtobin Sep 14 '13 at 10:30

1 Answers1

0

That is to prevent you from polluting the global namespace.

As explained in the documentation - lexical scope and variable safety:

all CoffeeScript output is wrapped in an anonymous function: (function(){ ... })(); This safety wrapper, combined with the automatic generation of the var keyword, make it exceedingly difficult to pollute the global namespace by accident.

garst
  • 6,042
  • 1
  • 29
  • 24