-
Notifications
You must be signed in to change notification settings - Fork 0
Modules
rmx edited this page May 30, 2016
·
1 revision
Since both client and server are written in CoffeeScript (JavaScript) it makes sense to share code between the two. Node already supports the CommonJS standard (require(), exports etc.), but browsers don't. On the clientside we therefore use https://github.com/sstephenson/stitch which allows us to use the exact same code and functions as under Node.
In CommonJS each file is a module and completely separated from the other modules. Modules interact with each other through exports and require(). A typical module will export a single class:
# File: foo.js
Parent = require 'parent'
class Foo extends Parent
constructor: (@v) ->
module.exports = Foo
You can then use the class as follows:
Foo = require 'foo'
fooInstance = new Foo 'x'