How do I define global variables in CoffeeScript?

后端 未结 8 2048
说谎
说谎 2020-11-22 05:41

On Coffeescript.org:

bawbag = (x, y) ->
    z = (x * y)

bawbag(5, 10) 

would compile to:

var bawbag;
bawbag = function(         


        
8条回答
  •  既然无缘
    2020-11-22 05:49

    Since coffeescript is rarely used on it's own, you can use global variable supplied by either node.js or browserify (and any descendants like coffeeify, gulp build scripts, etc).

    In node.js global is global namespace.

    In browserify global is equal to window.

    So, just:

    somefunc = ->
      global.variable = 123
    

提交回复
热议问题