0

Say I have the most basic CoffeeScript program possible that goes like:

console.log "Hello, World!"

But it's too complicated so I want to separate my program into multiple files.

#hello.coffee
console.log "Hello, #{stuff}!"

And

#stuff.coffee
stuff = "World"

What should be done to hello.coffee to know the variable stuff?

The catch of it is that I'd rather not have to do separate compiles to JS.

Code-MonKy
  • 2,026
  • 2
  • 14
  • 27
  • Possible duplicate of [How do I define global variables in CoffeeScript?](https://stackoverflow.com/questions/4214731/how-do-i-define-global-variables-in-coffeescript) – caffeinated.tech Nov 21 '18 at 14:09
  • So I can just add things to `window` like `window.stuff = "World"` and this will be available in another file like: `stuff = window.stuff`. Am I correct? – Code-MonKy Nov 22 '18 at 12:10
  • 1
    Yes, it will be available in all files on the global `window` object. But there is no need for `stuff= window.stuff`. You can just use `stuff` in another file (ie. `window.stuff` is the same as `stuff` given that there isn't another local `stuff` variable defined). – caffeinated.tech Nov 22 '18 at 12:47
  • Great, that should solve it. Thanks. – Code-MonKy Nov 22 '18 at 20:59

0 Answers0