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

224
Vistas
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
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