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

337
Views
What is the difference between Arrow Functions and Regular Functions when used for Class methods?

When working with Javascript objects, there is a big difference between using Arrow Functions compared to Regular Functions when it comes to this. For instance using a regular function here will properly bind this:

const person = {
  name: "Karen",
  age: 40,
  hi: function() {
    console.log("Hi " + this.name);
  }
}

person.hi() // "Hi Karen"

compared to using an Arrow Function which will incorrectly bind this:

const person = {
  name: "Karen",
  age: 40,
  hi: () => {
    console.log("Hi " + this.name);
  }
}

person.hi() // "Hi "

However, I am not sure if this difference applies when defining class methods. For instance, if I declare two methods - one as arrow function, one as regular function - they both seem to correctly bind this.

class Example {
  constructor() {
    this.values = [1, 2, 3, 4]
  }
  
  arrowMethod = (num) => {
    console.log(this.values.map((item) => item * num));
  }
    
  method(num) {
    console.log(this.values.map((item) => item * num));
  }
}

const example = new Example();
example.arrowMethod(2); // [2, 4, 6, 8]
example.method(2); // [2, 4, 6, 8]

So is there any reason to use one or the other when it comes to class methods?

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!