node.js - 关于一个events的问题,这段代码会无限循环吗?
ringa_lee
ringa_lee 2017-04-17 16:17:55
0
2
631
ringa_lee
ringa_lee

ringa_lee

reply all(2)
黄舟
const EventEmitter = require('events');

let emitter = new EventEmitter();
let n=1;
emitter.on('myEvent', () => {
    console.log(n++);
    ***emitter.emit('myEvent');***
});

***emitter.emit('myEvent')***;

There are two emitter.emit('myEvent');

Call event, the event itself also has a calling event, which creates a cycle. Finally, the call stack size is consumed and terminated.

For reference.

Love MongoDB! Have Fun!

伊谢尔伦

It will loop infinitely until the stack overflows... and then the process will be killed. Then there is no more...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template