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

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

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