To my understanding, the module system in Node (which is where the
require stuff comes from) returns whatever you supply to
module.exports. For example, most of the modules in my Atom packages follow the pattern:
something: (somethingElse) ->
# Do something cool ...
module.exports = Foo
This allows me to import the class
Foo someplace else by doing:
Foo = require './foo'
But you aren’t limited to exporting classes, you can export functions:
module.exports = (param) ->
# Do something cool
Which can then be used by:
foo = require './foo'
Or objects or whatever you can think of. Because a module can export whatever you like, you have to be careful to match up the calling protocol with the exporting protocol. Mismatches can be frustrating and, in my experience, hard to debug
You can even reference
module.exports multiple times like here:
Though, really the first reference on line 7 exports an object which is then amended on lines 24 and 25. So you’re really still only exporting one thing, an object.