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

225
Views
Is there an overhead to attaching many event listeners versus one iterating

Let's say I have a list of HTMLElement, and I want to check whether the composedPath contains the item, is there an overhead to doing this:

for (const item of list) {
    document.addEventListener("click", () => {
        if (event.composedPath.includes(item)) { doThing(item); }
    }
}

versus doing this:

document.addEventListener("click", () => {
    for (const item of list) {
        if (event.composedPath.includes(item)) { doThing(item); }
    }
}

Why would I even want to do it the first way? Because I'm working with Svelte (a component-based system like React), and it's easier to do things on a component-basis (e.g. cleaning up the event handler), rather than outside of it.

about 4 years ago · Juan Pablo Isaza
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!