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

75
Vistas
Access a method from an object inside of another method in JavaScript

imagine having this object :

var a = {
   b : () => console.log("yo"),
   c : () => b()
}

How can I execute the b function calling the c one ? the syntax above doesn't work... Do you have an idea ?

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

var a = {
   b : () => console.log("yo"),
   c : () => a.b() // reference to the object
}

or

var a = {
   b : () => console.log("yo"),
   c : function () {return this.b()} // use function syntax instead of lambda to gain a reference to the object on which c() is called
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

Maybe this works?

const a = {
  b : () => {console.log("yo")},
  c : () => {a.b()}
}

a.c()

about 4 years ago · Juan Pablo Isaza Denunciar

0

Instead of arrow functions use non-arrow functions, and then this will be available, if the method is called in the usual way:

var a = {
   b() { console.log("yo") },
   c() { return this.b() }
}

a.c();

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