const address={ name:"Peter", age: 26, something: () => { return this.innerHeight; } } console.log(address.something()) why this arrow function is referring 'this' as window object, when its parent scope is the address object? Can you please explain
ok, i got this. as per your definition, arrow function takes the scope of its parent, now the scope of its parent(address object) is global scope as address object can be used in the global code, that could be the reason for this behaivour, Please correct me if my understanding is wrong
If you are defining calcAge function inside John object, and if the calcAge function is an arrow function, then the this keyword inside that arrow function will point to global window object But, if the arrow function is defined inside a regular function, and that regular function is defined inside John object, in that case, this keyword in regular function will point to John object. And in turn, this keyword inside arrow function will also point to John object. Why? Because in arrow function, this keyword points to its immidiate sorrounding this keyword. In this case the immidiate sorrounding this is pointing to John object. Hope it make sense.
@@procademy thanks for clarification...I am glad and feel blessed to found such knowledgeable and informative channel on RUclips. Every developer should watch all J's watchlist.so beautifully explained. Thanks again for sharing with us.❤️🧡💛
I have a question why you don’t have one million sub man your content is so cool and amazing keep up man thank you very much
Your explanation is really great, i m so lucky to find such a great channel ❤️
I finally understand this. Thank you!
Very well explained, especially that this keyword in an arrow function uses the lexical this scope!
Great explanation! I am glad I found your channel. Thanks!
Thanks for watching!
how it behave when we use arrow function as method inside objection , please cover on this
const address={
name:"Peter",
age: 26,
something: () => {
return this.innerHeight;
}
}
console.log(address.something())
why this arrow function is referring 'this' as window object, when its parent scope is the address object? Can you please explain
ok, i got this. as per your definition, arrow function takes the scope of its parent, now the scope of its parent(address object) is global scope as address object can be used in the global code, that could be the reason for this behaivour, Please correct me if my understanding is wrong
If we make calcAge as a arrow function & we call like John.calcAge() then what will 'this' point to ? John object or window object?...
If you are defining calcAge function inside John object, and if the calcAge function is an arrow function, then the this keyword inside that arrow function will point to global window object
But, if the arrow function is defined inside a regular function, and that regular function is defined inside John object, in that case, this keyword in regular function will point to John object. And in turn, this keyword inside arrow function will also point to John object. Why? Because in arrow function, this keyword points to its immidiate sorrounding this keyword. In this case the immidiate sorrounding this is pointing to John object.
Hope it make sense.
@@procademy thanks for clarification...I am glad and feel blessed to found such knowledgeable and informative channel on RUclips. Every developer should watch all J's watchlist.so beautifully explained. Thanks again for sharing with us.❤️🧡💛
Please share this channel with others if you like my videos...🤝🤝
@@procademy sure