Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

303
Visualizações
Using this in functions: How does context work?
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda