Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

110
Vistas
Spreading new EventEmitter into object drops emitter methods
import EventEmitter from 'events';

const emitter = new EventEmitter();

const spread = { ...emitter };

console.log(spread.on); // undefined
console.log(emitter.on); // [Function: addListener]

Why does spreading drop this method? And how can I stop that from happening?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Why does spreading drop this method?

Because spread syntax only copies own, enumerable properties from the target. It doesn't copy inherited properties, and it doesn't copy the prototype of the object.

I'm not sure that you can clone an EventEmitter, but if you can it's not going to be a simple one-liner. You'd have to create a new instance, get the events it has listeners for (eventNames), then get the listeners for each event (listeners), etc. And even then, some things are subclasses of EventEmitter...

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda