In the following example:
const Auth = {
token : null,
setToken: (newToken) =>{
Auth.token = newToken
},
getToken : () =>{
return Auth.token
},
getTokenViaThis: () =>{
return this.token
},
setTokenViaThis: (newToken) =>{
this.token = newToken
}
}
Auth.setToken('hello')
Auth.setTokenViaThis('howdy')
console.log(Auth)
Auth.token = "hello" --> I would expect it to be "howdy"
Can someone explain what's the difference between setting a property on an object via objectName.property vs this.property. Because the setTokenViaThis is using an arrow function, I would expect the this to refer to the Auth object itself and behave the same way as Auth.token. It seems I'm missing something important here.