Top-level variables aren't globally-scoped and return values are mandatory in CoffeeScript

前端 未结 3 621
粉色の甜心
粉色の甜心 2021-01-21 04:19
funName = () ->
  $(\".foo\").addClass(\"bar\");

Compiles into the scope of an anonymous function. Calling funName from the console res

3条回答
  •  太阳男子
    2021-01-21 05:02

    I know this may be an older thread, but I've encountered the same problem and noticed an interesting command you can add into the compiler enviroment to fix this problem.

    The command -b or --bare is used to compile the JavaScript without the top-level function safety wrapper. After I added that command when I compiled my CoffeeScript file, it removed that odd wrapper:

    (function() {
        var funName;
        funName = function() {
           return $(".foo").addClass("bar");
        };
     }).call(this);
    

    I use WebStorm as my IDE enviroment and this is my compiler statement I use:

    --compile --bare $FileName$
    

提交回复
热议问题