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

87
Views
'this' is undefined when passing function signature as parameter

In the code bellow I'm passing a method of a class instance as callback argument to a another function. But this is undefined when I pass just the method signature. So I wonder what changes this according to the callback argument format. Is there some JS docs for this specific case?

class MyClass {
    foo = 'foo';
    bar() {
        console.log('This is:');
        console.log(this);
    }
}

const handler = (callback) => {
    callback()
}

const myClass = new MyClass()

handler(myClass.bar)
handler(() => myClass.bar())

Output:

This is:
undefined

This is:
MyClass {foo: 'foo'}
about 4 years ago · Juan Pablo Isaza
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!