forked from TrainingByPackt/Professional-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise67.js
More file actions
26 lines (18 loc) · 681 Bytes
/
Exercise67.js
File metadata and controls
26 lines (18 loc) · 681 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const EventEmitter = require('events');
const emitter = new EventEmitter();
emitter.emit('my-event', { value: 'event value' });
emitter.on('my-event', (value) => {
console.log(value);
});
emitter.emit('my-event', { value: 'another value' });
emitter.on('my-event', (value) => {
console.log('i am handling it again');
});
emitter.emit('my-event', { value: 'new value' });
function handleEvent(event) {
console.log('i am handling event type: ', event.type);
}
emitter.on('event-with-type', handleEvent);
emitter.emit('event-with-type', { type: 'sync' });
emitter.removeListener('event-with-type', handleEvent);
emitter.emit('event-with-type', { type: 'sync2' });