小编Jar*_*tin的帖子

CoffeeScript中的Node.js module.exports

我正在研究一个简单的例子; 我可以使用Javascript,但我的CoffeeScript版本有问题.

这是person.coffee:

module.exports = Person

class Person 
    constructor: (@name) ->

    talk: ->
        console.log "My name is #{@name}"
Run Code Online (Sandbox Code Playgroud)

这是index.coffee:

Person = require "./person"
emma = new Person "Emma"
emma.talk()
Run Code Online (Sandbox Code Playgroud)

我期望运行index.coffee并看到控制台输出"我的名字是艾玛".相反,我收到一个错误说TypeError:undefined in not a function.

node.js coffeescript

19
推荐指数
3
解决办法
2万
查看次数

标签 统计

coffeescript ×1

node.js ×1