在CofeeScript中,我通过执行以下操作创建一个全局对象:
window.App =
init : ->
...
运行
coffee -w app.coffee
会提示window is not defined
,并且不会重写app.js
文件。但是,运行
coffee -c app.coffee
可以毫无问题地进行编译。如何获得
coffee -w
接受全局window
?CoffeeScript版本为1.1.1(来自
coffee -v
)谢谢!
最佳答案
如果要观看文件并进行编译,则需要执行以下操作:
coffee -wc file.coffee
Using only the -w
flag causes coffee to just run the script when it changes, as if you had run:
coffee file.coffee
In regards to the window is not defined
error, if you want to make your script runnable both in a browser and in node.js, then you can do this:
root = exports ? this
class Thing
constructor: (@name) ->
whoAreYou: ->
alert @name
root.Thing = Thing
另一个有用的标志组合是
-wp
,它在每次更改文件时仅通过管道将编译javascript标准化。
关于CoffeeScript:coffee -w-file-of.file.coffee提示: “window is not defined”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6347671/