Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

188
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda