I have 2 class files:
foo.coffee: class Foo
bar.coffee: class Bar extends Foo
How do I define these classes so they are globally available? I get the error in Bar that Foo is not defined.
I have an index.js file that I call node on to run the scripts. Here is the contents of index.js, I most likely did this wrong also:
exports.Foo = require("./foo")
exports.Bar = require("/bar")
foo.coffee:
bar.coffee:
index.coffee:
UPDATE: You also need to run
.coffeefiles withcoffee, unless you compile them first.UPDATE 2: How you structure your models is up to you. I like the pattern above (where simple modules export just a function — that’s when you need to assign to
module.exportsbecause you can’t simply assign toexports) but others prefer a structure like this:foo.coffee:
bar.coffee:
index.coffee:
Where each module exports an object with one or more properties.