我不确定为什么这不起作用。有人可以给我线索吗?我没有看到任何事件被记录下来,但它们确实得到emitted
了……嗯,我想:)
{EventEmitter} = require 'events'
class Base extends EventEmitter
class App extends Base
constructor: (cb) ->
console.log 'setup'
@on 'listener:1', (data) ->
console.log 'listener 1: ' + data
@on 'listener:2', (data) ->
console.log 'listener 2: ' + data
cb()
class One extends Base
fire: () ->
console.log 'fire 1'
@emit 'listener:1', 1
class Two extends Base
fire: () ->
console.log 'fire 2'
@emit 'listener:2', 2
new App(
() ->
setTimeout (->
one = new One()
one.fire()
setTimeout (->
two = new Two()
two.fire()
), 2000
), 2000
)