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

187
Vistas
Remove eventlistener

Help:-) How do i remove this listener?

this.overlay.addEventListener('click', this._handlePlay.bind(this));

_handlePlay looks like this:

_handlePlay() {
    this._isOpen = !this._isOpen;
  }

i tried...

this.overlay.removeEventListener('click', this._handlePlay.bind(this));

and more desperately:

this.overlay.removeEventListener('click', this._handlePlay());

but the listener wont leave the scene?

I have the bind as I am in js and web component context

/regards

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

0

The function you pass to removeEventListener needs to be the same function that you pass to addEventListener.

bind creates a new function.

this.overlay.addEventListener('click', this._handlePlay.bind(this));

Since you don't keep the value of this._handlePlay.bind(this), there's no way to get that function back to pass it to removeEventListener.


You need to keep the value somewhere that you can access when you later try to remove the event listener.

const boundHandlePlay = this._handlePlay.bind(this);
this.overlay.addEventListener('click', boundHandlePlay);
this.overlay.removeEventListener('click', boundHandlePlay);
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