Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

72
Views
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 answers
Answer question

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 Report

0

Maybe this works?

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

a.c()

about 4 years ago · Juan Pablo Isaza Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!