The first thing you need: you do not need require 'coffee-script'
- perhaps it is with coffee
; similar to running compiled JavaScript. You do not need the CoffeeScript library available at runtime of your program.
Secondly, the first file has the wrong indent; if you want this to be a Mic
constructor, backtrack it one level below the class
, i.e.:
class Mic constructor: (x) -> @t = [] @t.push x exports.Mic = Mic
Finally, the problem is that exports
is an export object . See here:
exports.Mic = Mic
You assigned Mic
to the exports
Mic
object, so now exports
in Mic.coffee looks like this:
{ Mic: ...your class... }
When you say require './Mic'
, you return this object; in other words:
require('./Mic') == { Mic: ...your class... }
So you need to do one of the following:
Export Mic
as all Mic.coffee exports, not as a key:
module.exports = Mic
Extract the entire module, and then instantiate the Mic
object inside:
mic = require './Mic' m = new mic.Mic 3
Take Mic
out of the require
module:
{Mic} = require './Mic'
source share