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

109
Views
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 answers
Answer question

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