我想我一直在遭受一个非常奇怪的错误。 使用EventEmitter可能会系统地破坏某些东西。 自从我开始使用once功能以来,事情似乎已经消失。
以下控制台输出行演示了正在发生的事情:
var EventEmitter = require('events').EventEmitter; a = new EventEmitter(); a.on("bla", function() { console.log("perm");}); a.once("bla", function() { console.log("this is temp"); }); a.emit('bla');您可能希望调用这两个事件,但在我的控制台上输出为:
> a.emit("bla") perm perm true这是怎么回事??
我也尝试在脚本中使用代码,这似乎有效,但我感觉到once功能在某种程度上导致了我服务器上的奇怪故障。
有没有遇到过这个?
[测试版本0.5.1和0.5.3]
I think I've been suffering from a very strange bug. There might be something systematically broken with EventEmitter. Ever since I started using the once function things seem off.
The following lines of console output demonstrate what's happening:
var EventEmitter = require('events').EventEmitter; a = new EventEmitter(); a.on("bla", function() { console.log("perm");}); a.once("bla", function() { console.log("this is temp"); }); a.emit('bla');You would expect both events to be called, but on my console the output is:
> a.emit("bla") perm perm trueWhat's going on??
I've also tried using the code in a script and that seemed to work but I'm getting the feeling that the once function is somehow responsible for the weird glitches on my server.
Anyone ever encountered this?
[Tested on versions 0.5.1 and 0.5.3]
最满意答案
适用于我的0.5.10。 我很确定你输入的内容不是你发布的内容 - 第二个“烫发”来自哪里? 再试一次。
$ node > var EventEmitter = require('events').EventEmitter; > a = new EventEmitter(); {} > a.on("bla", function() { console.log("perm");}); { _events: { bla: [Function] } } > a.once("bla", function() { console.log("this is temp"); }); { _events: { bla: [ [Function], [Object] ] } } > a.emit('bla'); perm this is temp true >Works for me on 0.5.10. I'm pretty sure you typed something else than what you posted here - where could the second "perm" come from? Try it again.
$ node > var EventEmitter = require('events').EventEmitter; > a = new EventEmitter(); {} > a.on("bla", function() { console.log("perm");}); { _events: { bla: [Function] } } > a.once("bla", function() { console.log("this is temp"); }); { _events: { bla: [ [Function], [Object] ] } } > a.emit('bla'); perm this is temp true >更多推荐
发布评论