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

175
Vistas
setTimeout(window.location.reload,1000) not working

Why does this not work?

setTimeout(window.location.reload, 1000)

This does

setTimeout(() => window.location.reload(), 1000)

The first parameter is a function. Shouldn't the first example work?

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

0

The problem is that you are passing a loose reference to the reload function; therefore, losing its binding to window.location.

You can use the following to prove the point (It may not work

setTimeout(window.location.reload.bind(window.location), 1000)

But I think adding a function wrapper makes it easier to understand.

Example

const a = {
  value: 2,
  b: function() {
    console.log(this.value);
  }
}

a.b();

const b = a.b;
b();

const boundB = b.bind(a);
boundB();

Summary Using syntax like a.b() makes sure that b is called with a as its this.

Calling a function without a . before will the function as a global, which will pass window as this in sloppy mode and null as this in strict mode.

This can always be overriden by binding function or by using arrow functions (which take its this from the surrounding this) or if you bind your function ahead of time.

about 4 years ago · Juan Pablo Isaza Denunciar

0

It won't work as the scope of calling window.location.reload will be window instead of window.location. Try this:

window.location.reload.call(window);

vs.

window.location.reload.call(window.location);
about 4 years ago · Juan Pablo Isaza Denunciar

0

This post sums it up nicely https://stackoverflow.com/a/10840058/10853009

Because reload() needs window.location as this. In other words - it is a method of window.location. When you say:

var fun = window.location.reload;

fun();

You are calling reload() function without any this reference (or with implicit window reference).

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