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

144
Visualizações
Object with 2 methods. Method A, Method B. Calling Method B from within Method A

Say I have two methods on an Object.

Object = {
    MethodA() {
        console.log('A')
    },

    MethodB() {
        this.MethodA()
    }
}

The MethodA doesn't get called. why is this and how can I learn more about what I am doing wrong. What is the terminology called and where is this explained in the ECMA standard?

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

0

Because this will be determined by the context in which the method is called and will not always refer to the object.

const object  = {
    MethodA() {
        console.log('this in A: ', this === window ? 'window' : this)
    },

    MethodB() {
        console.log('this in B: ', this === window ? 'window' : this)
        object.MethodA()
    }
}

object.MethodB() // this in B === object

const b = object.MethodB;

b() // this in B === window

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