Something seems off about the context in this code. I've left comments to describe my issue below:
const cat = {
//arrow function
meow: () => {
console.log(this);
},
makeMeow(){
// Why does 'this' refer to the window object here?
// The parent scope of meow function is the cat object,
// so should not 'this' refer to the cat object instead?
this.meow();
},
};
cat.makeMeow(); // This function is causing the problem
I'm puzzled as to why WHY cat.makeMeow()
prints the window object. The expected behavior would be for it to reference the cat object.