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

148
Views
no se puede vincular esto a la función

Tengo un elemento DOM btn y tengo una función con setTimeout que escucha en este elemento. Quiero eliminar mi oyente mientras se ejecuta la función para evitar múltiples llamadas de setTimeout y la superposición de tiempo, pero esto en mi función de devolución de llamada es una ventana. Intenté usar bind pero no funciona

 const checkTable = () => { this.removeEventListener('click', checkTable); console.log(this); // i get "window" setTimeout(() => { //some code }, 3000); }; const app = () => { const checkBtn = document.querySelector('.check-btn'); checkBtn.addEventListener('click', checkTable.bind(checlBtn)) }; app();

y el mismo resultado con el evento onclick

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

0

No puede llamar a .bind() en una función de flecha . Las funciones de flecha se usan para usar automáticamente this valor desde donde se define. Para que esto funcione, su checkTable debe ser una función "normal".

 function checkTable() { this.removeEventListener('click', checkTable); console.log(this); // i get "window" setTimeout(() => { //some code }, 3000); }
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!