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

156
Views
Why is 'this' arrow function behaving differently in Javascript Classes vs Object Literal

I am cofused about the behaviour of arrow functions. Please look at the following example:

class Test {
  foo2 = () => {
    console.log(this)
  }
}
let t1 = new Test

let Test2 = {
  foo2: () => {
    console.log(this)
  }
}

t1.foo2()
Test2.foo2()

Test2.foo2() returns an empty object which makes sense as arrow functions doesn't have there own "this", but why is t1.foo2() logging t1 object? Aren't both the situations same ?

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!