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

186
Views
Quitar detector de eventos

Ayuda:-) ¿Cómo elimino este oyente?

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

_handlePlay se ve así:

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

Lo intenté...

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

y más desesperadamente:

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

pero el oyente no abandonará la escena?

Tengo el enlace como estoy en js y contexto de componente web

/Saludos

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

La función que pasa a removeEventListener debe ser la misma función que pasa a addEventListener .

bind crea una nueva función.

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

Dado que no mantiene el valor de this._handlePlay.bind(this) , no hay forma de recuperar esa función para pasarla a removeEventListener .


Debe mantener el valor en algún lugar al que pueda acceder cuando más tarde intente eliminar el detector de eventos.

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