2013-10-15 25 views
0

說我有一個名爲participant.coffee在其文件中,有兩個類:如何從單個文件導出多個類?

class ParticipantData 
    constructor: (data) -> 
      # whatever 

    doSomething: 
      console.log 'participant data!' 

class ParticipantResult 
    doAnotherThing: 
      console.log 'participant result!' 

module.exports = new ParticipantResult() 

現在我可以用require('.particpantresult')訪問ParticipantResult,但我想不出任何方法來調用ParticipantData的構造。是否有可能訪問ParticipantData而不將其移動到它自己的文件?

回答

1

返回與該構造的對象,然後調用那些:

module.exports = { 
    ParticipantData: ParticipantData, 
    ParticipantResult: ParticipantResult 
}; 

與使用分類代碼:

var dm = require("..."); 
var myParticipantResult = new dm.ParticipantResult(); 
相關問題