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

163
Visualizações
why "this" keyword in arrow function represents the object rather than global object(window)

I am learning the behavior of this keyword in ES6 class , before I have learnt that this keyword in object functions, represent the following :

  • In regular function, this represents the the current object.
  • In arrow function, this represent the global object(window).

So, when I worked with ES6 class I see that Class behave as Object when it is complied into JavaScript ,I see this behavior in console by putting this in a class method and this was representing the current class as Object as well as its prototype was Object.

For conceptual understanding, I make one Arrow function foo() and one Regular function bar() in a class AppComponent and print this keyword as follow:

enter image description here

I was expecting that this in foo() would represent global object(window) , because it is inside Arrow function in the Object and ,on the other side,in the bar() this represent the current object due to Regular function inside object which is AppComponent, but the output was:

enter image description here

bar() output is expected.

foo() output is unexpected.

So, my question is that why this represent the current Object Appcomnent rather than global object(window), because it is inside the arrow function in the object .

Please correct me if my concept is not correct in the question ,if it is correct then why I see the unexpected output. I would very thankful to you for your contribution.

about 4 years ago · Juan Pablo Isaza
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