文件1:
module.exports = {
class Verify
myMethod: ->
# return stuff
和file2:
Verify = require('excelTest.js')
verify = new Verify
verify = verify.myMethod()
以上失败:
Running "coffee:glob_to_multiple" (coffee) task
>> server/api/abrechnung/excelTest.coffee:7:2: error: unexpected class
>> class Verify
>> ^^^^^
>> In file: server/api/abrechnung/excelTest.coffee
>> On line: 6
>> class Verify
>> ^
答案 0 :(得分:2)
module.exports.Verify = class Verify
mymethod: ->
..
或者,可能更具可读性,将类定义及其导出分开:
class Verify
mymethod: ->
..
module.exports =
Verify: Verify
在这两种情况下,它都是require('excelTest.js').Verify
;如果您只是想要Verify
,请忽略额外的require('excelTest.js')
。