node js event emitter
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:
- display none in jquery
- jquery ajax upload image
- how to edit a fil with vanilla js
- package json scripts multiple commands
- same name different extentions react-native android
- jquery get second td of tr
- how to output to console java
- render react in blaze
- javascript get array of class names
- how to get cwd nodejs
- using if statements in javascript
- js check if array
- jquery replace text
- universal apollo kit
- latest rn fatch blob package download
- command reboot android app react native adb command
- js replace all
- javascript example of foreach loop
- how to fill false into array javascript
- javascript character ascii value modify
- socket io get ip
- js date enlever jour
- file input disable open file picker javascript
- jquery selected option value