If I have a CoffeeScript class defined in a separate file, which I’m calling from my main script, I can make the functions within the file globally visible, but not the class.
The included file is:
root = exports ? this
root.add = (a, b) ->
return a + b
class root.userModel
username: 'Aaaa'
name: 'Bbbb'
I can access the function from my main code. How can I create the class?
Your code will indeed make
userModela global, assuming thatexportsis undefined andthisiswindow. If you’re having problems, check those conditions.