Export a class from a Coffeescript file Export a class from a Coffeescript file node.js node.js

Export a class from a Coffeescript file


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.


The class ... form is an expression that returns a value. So, you'll want to assign the result of that class expression to a property on your export object. Like so:

root.userModel = class userModel  username: 'Aaaa'  name: 'Bbbb'

Update:

Oops, not true, should work fine either as class root.userModel or as root.userModel = class userModel.


just define your class with a '@' before its name

class @ClassName  blablabla: -> blablalblablabla