0

I have this object

const data = {
  users: require("../model/users.json"), // initial value
  setUsers: (newUsers) => {
    this.users = newUsers
 } 
}

The setUsers arrow function doesn't assign newUsers to this.users, like it doesn't have access to this.users. But if I change setUsers to a regular function it works.

setUsers: function (newUsers) {
    this.users = newUsers
 } 

Now it assigns newUsers to this.users. Why it does that, I thought arrow functions and regular functions are the same?

m_jdm35
  • 25
  • 1
  • 5
  • 1
    Regarding "I thought arrow functions and regular functions are the same" ... see [5 Differences Between Arrow and Regular Functions](https://dmitripavlutin.com/differences-between-arrow-and-regular-functions/). – jarmod Aug 28 '23 at 16:52
  • They are not the same, thanks. – m_jdm35 Aug 29 '23 at 12:12

0 Answers0