In CofeeScript I am creating a global object by doing this:
window.App =
init : ->
...
Running coffee -w app.coffee
complains window is not defined
and doesn't rewrite the app.js
file.
However, running coffee -c app.coffee
compiles without a problem.
How can I get coffee -w
to accept global window
?
CoffeeScript version is 1.1.1 (from coffee -v
)
Thanks!
If you want to watch a file and have it compiled you need to do:
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
Another useful flag combination is -wp
which just pipes the compile javascript to standard out each time you make a change to the file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With