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

158
Visualizações
Trying to understand difference beetween functions arrow and functions in javascript

I'm trying to understand the difference beetween functions arrow and functions in javascript, with the help of some website, and from what I seemed to understand, it's the this binding that change in the case So I understood that in function arrow, this is binded to the closest non-arrow function parent this and in regular function, this is binded from the closest this

So with that in mind, I was doing some test in the browser console and came up with this:

test = {
    test_name: "OK",
    test_func: function() {
        console.log(this.test_name);
        (() => {
            console.log(this.test_name);
            function b() {
                console.log(this.test_name);
            }
            b();
        })();
    }
}
test.test_func();

I was excepting to get

OK
OK
OK

but what I get is

OK
OK
undefined

And I can't understand why since I get 'OK' in the arrow function, why don't I get 'OK' in the b() function?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

From w3schools:

The handling of this is also different in arrow functions compared to regular functions.

In short, with arrow functions there are no binding of this.

In regular functions the this keyword represented the object that called the function, which could be the window, the document, a button or whatever.

With arrow functions the this keyword always represents the object that defined the arrow function.

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