After coffeescript is compiled into js, it calls its function with js in the front end.

  node.js, question

For example, I wrote a function in coffeescript inside:

abc=->
 1 plus 1

After compiling into js, it is:

(function() {
 
 var abc;
 abc = function() {
 Return 1 plus 1;
 };
 
 }).call(this);

Then I quoted the compiled js in html inside:

<script src="js/js.js"></script>
 <script type="text/javascript">
 alert(abc());
 </script>

But the abc function cannot be found
It is only after this layer of bread has been removed.

Should be abc into a local function …
What should I do? Can’t you manually remove the wrapped. call(this) after each compilation?

Ps: It’s the default compilation method. What’s the advantage of wrapping it up like this? Or is it just good when applied to nodejs?

Add@Neil_ LuThe answer.

The default behavior of the coffee compiler avoids variable contamination, because when using coffee-script for development, the declaration and use of variables are “invisible” to developers, so variable contamination is extremely easy to occur. Therefore, during the development process, it is not recommended to remove the wrapper. If you need to declare as a global variable and know its risks, you can adopt the following methods:

coffeeabc=@abc=()->
 …
 …