First I tried this -
const profile = {
name: 'Alex',
getName: function(){
return this.name;
}
};
Which works fine. Now I tried the same thing with fat arrow. In that case "this" is coming undefined.
const profile = {
name: 'Alex',
getName: () => {
return this.name;
}
};
This gives me an error
TypeError: Cannot read property 'name' of undefined
What I learned was, fat arrow syntaxes are way better handling implicit "this". Please explain why is this happening.