I’m working on a simple example; I can get it to work with Javascript, but there is something wrong with my CoffeeScript version.
Here is person.coffee:
module.exports = Person
class Person
constructor: (@name) ->
talk: ->
console.log "My name is #{@name}"
And here is index.coffee:
Person = require "./person"
emma = new Person "Emma"
emma.talk()
I am expecting to run index.coffee and see the console output “My name is Emma”. Instead, I am getting an error saying TypeError: undefined in not a function.
Put the
module.exportsline at the bottom.—-person.coffee—-
When you assign to
module.exportsat the top, thePersonvariable is stillundefined.