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

143
Vistas
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 Respuestas
Responde la pregunta

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 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