Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

177
Views
¿Puedo poner un emisor de eventos en un nodo de clase js?

Tengo esta clase:

 class test { constructor(name) { this.name = name } }

Así que quiero tener un evento en la clase que se pueda llamar afuera.

Aquí el archivo completo:

 const eventLib = require('events'); const myEmitter = new eventLib.EventEmitter(); class test { constructor(name) { this.name = name } }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede subclasificar el EventEmitter para que su clase tenga todos los mismos métodos que un objeto EventEmitter o puede colocar un eventEmitter en los datos de su instancia y usarlo allí.

Aquí está la subclasificación:

 const EventEmitter = require('events'); class Test extends EventEmitter { constructor(name) { super(); this.name = name this.on("hi", () => { console.log("got hi: ", this.name); }); } } let x = new Test("Bob"); x.emit("hi");
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!