eventemitter nodejs
const EventEmitter = require('events');
class MyEmitter extends EventEmitter {
foo() {
this.emit('test');
}
}
const myEmitter = new MyEmitter();
myEmitter.on('test', () => console.log('Yay, it works!'));
myEmitter.foo(); // Yay it works!const myEmitter = new MyEmitter();
let m = 0;
myEmitter.on('event', () => {
console.log(++m);
});
myEmitter.emit('event');
// Prints: 1
myEmitter.emit('event');
// Prints: 2myEmitter.on('status', (code, msg)=> console.log(`Got ${code} and ${msg}`));
Also in JavaScript:
- javascript variable declaration
- bind and unbind jquery validation
- react native expo search bar
- add st nd rd th javascript
- body parser express
- node ubutun
- how to send array to js file in wplms
- js if array is 2d
- how to run node js with proxy
- double click on element using javascript
- store console.timeEnd in variable js
- jquery select self and siblings
- what is payload in redux
- bot prefix discord.js
- enable emmet vscode react
- trim white spaces in js
- create global variable inside function JavaScript
- javascript convert milliseconds to hh mm ss
- json in uipath
- append meta tag to head javascript
- how to submit a form in js
- load js
- js string to node
- string contains character javascript