Skip to content

关于Events #81

@royIdoodle

Description

@royIdoodle

url:https://elemefe.github.io/node-interview/#/sections/zh-cn/event-async
Events 中
有下面的描述

以及这样会不会死循环?

const EventEmitter = require('events');

let emitter = new EventEmitter();

emitter.on('myEvent', function sth () {
// 下面的代码是不是写错了?应该是 emitter.emit('myEvent')吧
  emitter.on('myEvent', sth);
  console.log('hi');
});

emitter.emit('myEvent');

能否再进一步解释一下,两种事件触发有啥区别?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions