【发布时间】:2011-12-21 18:39:39
【问题描述】:
我想要这样的作品:
var Events=require('events'),
test=new Events.EventEmitter,
scope={
prop:true
};
test.on('event',function() {
console.log(this.prop===true);//would log true
});
test.emit.call(scope,'event');
但是,不幸的是,监听器甚至没有被调用。有没有办法用 EventEmitter 做到这一点?我可以Function.bind 给听众,但是,我真的希望EventEmitter 有一些特殊的(或明显的;)方法来做到这一点......
感谢您的帮助!
【问题讨论】:
标签: javascript node.js scope eventemitter