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

147
Vistas
can't bind this to function

I have a DOM element btn and have function with setTimeout which listens on this element. I want to remove my listener while function is running to prevent multiple calls of setTimeout and time overlapping, but this in my callback function is window? I tried to use bind but it's not working

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();

and the same result with onclick event

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

0

You can't call .bind() on an arrow function. Arrow functions are used to automatically use the this value from where it's defined. For this to work, your checkTable needs to be a "normal" function.

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