Coffeescript wrapping files in a function

后端 未结 2 1741
清酒与你
清酒与你 2020-12-30 11:23

The coffeescript compiler is, for some reason, wrapping all of my .coffee files in a function when they are compiled. For example, if I have test.coffee:

cla         


        
2条回答
  •  一生所求
    2020-12-30 11:51

    Never add event listeners in HTML. Add them in your JavaScript, preferably in the same scope in which you define the event handler.

    printAValue = () -> 
        test = new TestClass()
        test.printValue()
    
    document.body.addEventListener('load', printAValue, false)
    

    If you absolutely need to export something to the global scope, export to the window object:

    window.printAValue = () -> 
        test = new TestClass()
        test.printValue()
    

提交回复
热议问题