Hello there, I'm a beginner so please forgive me for any lack of knowledge.
const example = {
myFunction(){
console.log(this);
},
myFunction2(){
function myFunction3(){
console.log(this)
}
return myFunction3()
} }
When I execute the code
example.myFunction2()
I get the global window object. I'm a bit perplexed by this. My inquiries are:
- Can
myFunction2()
accessmyFunction3()
because of their hierarchy? If so, is there a way to directly accessmyFunction3()
without going throughmyFunction2()
? - Why does
this
inmyFunction3()
return the global window instead of referencingmyFunction3()
itself?
Thank you for your assistance!