我对使用 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) ->
至:
constructor: (id) ->
关于javascript - CoffeeScript 和 Node 中的静态方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10460354/