Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export a class from a Coffeescript file

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?

like image 428
tooba Avatar asked Sep 23 '11 18:09

tooba


1 Answers

Your code will indeed make userModel a global, assuming that exports is undefined and this is window. If you're having problems, check those conditions.

like image 127
Trevor Burnham Avatar answered Sep 23 '22 03:09

Trevor Burnham