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

181
Views
Why does the pointing of `this` not change
let o = {
  a: 123,
  b: function () {
    console.log(this, this.a);
  },
};

(o.b)()

Like this code, my understanding is that the code is like this:

const b = o.b
b() // this is pointing to window

But for (o.b)(), this keyword is pointing the o object, why is that?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Putting parentheses around an object reference to a function will only change the this from the object if there's something else inside the parentheses that makes the interpreter first resolve the value inside the parentheses to something else first (for example, if you use any of the operators, or invoke a function inside the parentheses).

let o = {
  a: 123,
  b: function () {
    console.log(this === window);
  },
};

// Using comma operator now
(0, o.b)()

But if all you have is a plain method reference on an object, with nothing else inside the parentheses, the calling context doesn't change - the extra parentheses around the reference doesn't change it.

about 4 years ago · Santiago Trujillo 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!