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

300
Vistas
Using this in functions: How does context work?
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

this points to the context. In event handlers, this is the element that received the event (the button, the div, the link...). If you call a function as if it were a method, this is the object. But the fact that the function is declared as a method does not ensure that it is called as such.

For example:

If you are in the global context (you are not inside any function), this is window

 console.log(this===window); function test() { console.log(this===window); if (this!==window) { console.log(this); } } test();

this is window

But if that function is an attribute of an object, then this becomes that object:

 function test() { console.log('Es window?:' + (this===window)); if (this!==window) { console.log('Es obj?:' + (this===obj)); } } console.log('Modo no estricto'); var obj={ prueba: 'hola' } test(); console.log('Como método'); obj.metodo=test; obj.metodo();


over 4 years ago · Santiago Trujillo 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