Javascript coffeescript和node中的静态方法

Javascript coffeescript和node中的静态方法,javascript,node.js,coffeescript,Javascript,Node.js,Coffeescript,我对使用coffeescript相当陌生,我有以下代码 eventBus = require './eventBus' class Aggregate constructor(id) -> @_id = id

我对使用coffeescript相当陌生,我有以下代码

eventBus = require './eventBus'                      

class Aggregate                                       
  constructor(id) ->                                  
    @_id = id                                         

  @find: (id) ->                                                              
    console.log "Find Called"
    new Aggregate(id)                                                 

  @apply: (event) ->                                                          
    @_total += event.attribute.amount                                         

  @emit: (event) ->                                                           
     EventBus.store event                                                     

module.Aggregate = Aggregate
我的问题是我想打电话给Aggregate.find 20 这反过来将返回一个具有该ID的新聚合。任何关于如何使该模块像这样工作的建议都将不胜感激


为迈克干杯。

除了构造函数中有语法错误外,您的代码应该可以正常工作

更改:

constructor(id) ->
致:

将此附加到某个位置:

Aggregate.find = (id) ->                                                              
  console.log "Find Called"
  new Aggregate(id)                                                 

这将是“静态”方法。

PS:
new@(id)
在类方法中做了正确的事情:在类上下文中使用
@
可以做到这一点,因此他的
find
方法已经在正确的位置。
Aggregate.find = (id) ->                                                              
  console.log "Find Called"
  new Aggregate(id)