I created the object in the code below:
let o = {
name: 'object',
getName(){
console.log(this.name);
}
}
o.getName();
the key word this in the method refers to the object o.
but when I use arrow function like bellow :
let o = {
name: 'object',
getName: ()=>{
console.log(this.name);
}
}
o.getName();
here the key word this refers to the global this not the object o.
could someone explain the reason why ? thank you