// jsdrops.com/arrow-functions
this.whoIsThis = 'TOP'; // Identify this scope
// Defining
const fancyObj {
whoIsThis: 'FANCY', // Identify this object
regularF: function () {
console.log('regularF', this.whoIsThis);
},
arrowF: () => {
console.log('arrowF', this.whoIsThis);
},
};
// Calling
console.log('TOP-LEVEL', this.whoIsThis); // It's "TOP" here
fancyObj.regularF(); // Output #1
fancyObj.arrowF(); // Output #2
fancyObj.regularF.call({whoIsThis: 'FAKE'}); // Output #3
fancyObj.arrowF.call({whoIsThis: 'FAKE'}); // Output #4
Having troubles? Email us at [email protected]