“Acara NodeJS” Kode Jawaban

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

Acara NodeJS

const EventEmitter = require('events');

class MyEmitter extends EventEmitter {}

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

Buat nodej acara

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

Jawaban yang mirip dengan “Acara NodeJS”

Pertanyaan yang mirip dengan “Acara NodeJS”

Lebih banyak jawaban terkait untuk “Acara NodeJS” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya