“NodeJS -Ereignis” Code-Antworten

Knoten 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!
garzj

NodeJS -Ereignis

const EventEmitter = require('events');

class MyEmitter extends EventEmitter {}

const myEmitter = new MyEmitter();
myEmitter.on('event', () => {
  console.log('an event occurred!');
});
myEmitter.emit('event');
Arsham

Machen Sie Event Nodejs

const events = require('events');

let emitter = new events.EventEmitter();

emitter.on('newEvent', (message)=>{
	
	console.log(`Message : ${message}`);
});

emitter.emit('newEvent', 'Hello guys, this is CodezUp');
Thoughtless Tamarin

Ähnliche Antworten wie “NodeJS -Ereignis”

Fragen ähnlich wie “NodeJS -Ereignis”

Weitere verwandte Antworten zu “NodeJS -Ereignis” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen