// this = reference to the object where THIS is used // (the object depends on the immediate context) const person1 = { name: "Spongebob", favFood: "hamburgers", sayHello: function(){console.log(`Hi! I am ${this.favFood}`)}, eat: function(){console.log(`${this.name} is eating ${this.favFood}`)} } const person2 = { name: "Patrick", favFood: "pizza", sayHello: function(){console.log(`Hi! I am ${this.favFood}`)}, eat: function(){console.log(`${this.name} is eating ${this.favFood}`)} } person1.eat(); person2.eat();
I've seen people saying it's pretty easy to get confused with which object 'this' is referring to. I haven't learned enough to know good JS practices, but it's good to keep it in mind so I know I need to learn this at some point
This is great! Can you explain in more detail in a later video on why arrow functions don't recognize "this?" I understand it has to do with scope, but I'm not quite wrapping my head around how arrow functions handle scope differently. Thanks again for your time and expertise sharing this!
bro how do u have time to watch all these cartoons like in another video of yours i saw an example of pokemons and it was like that u know and follow pokemon till date, whereas i do coding all day like 10hrs per day but how do u have so much time 😭😭 btw love your teaching style u make everything look so easy thanks a lot man
since it is the same as writing the name of the object, is this keyword used in case there are nameless things? or so that you can use the same code for different objects since it automatically updates the object name in the method? Thanks so much bro, even if you don't answer, I know you've got work to do ❤
I still feel confused with those different ways of writing functions. What are the differences between them? why doesn't the arrow function refer to the object in which it was written when using 'this'?
What does it think 'name' is if it's not 'this.name'? EDIT: Oh is it because everything inside the function is inside the local scope of the function and NOT the local scope of the object? Therefore the object key-values aren't passed into the function without 'this'?
// this = reference to the object where THIS is used
// (the object depends on the immediate context)
const person1 = {
name: "Spongebob",
favFood: "hamburgers",
sayHello: function(){console.log(`Hi! I am ${this.favFood}`)},
eat: function(){console.log(`${this.name} is eating ${this.favFood}`)}
}
const person2 = {
name: "Patrick",
favFood: "pizza",
sayHello: function(){console.log(`Hi! I am ${this.favFood}`)},
eat: function(){console.log(`${this.name} is eating ${this.favFood}`)}
}
person1.eat();
person2.eat();
Are you github ?
was struggling with THIS keyword you cleared it in just 5 min dude you are one of the best teacher on youtube
I've seen people saying it's pretty easy to get confused with which object 'this' is referring to. I haven't learned enough to know good JS practices, but it's good to keep it in mind so I know I need to learn this at some point
Hands down, best programming instructor on TH-cam. Simple and clean explanations.
This is great! Can you explain in more detail in a later video on why arrow functions don't recognize "this?" I understand it has to do with scope, but I'm not quite wrapping my head around how arrow functions handle scope differently. Thanks again for your time and expertise sharing this!
hands-down this is the best & shortest explanation for this keyword
Bro just "de-obfuscated" my mind.
Appreciated and subscribed.
I was struggling with the 'this' keyword a bit as a novice programmer, but this video made it clear as day. Thank you so much!
Actually, I was searching for this content. It's really helped me.
Thank you so much❤
Your videos are amazing! To the point, clear, well illustrated. It has helped me grasp a few concepts better.
by far the greatest code learning channel I have seen 🙇♂🙏🙏🙏🔥🔥🔥🔥
Woww, struggling it for hours. But you made me understand about it within 4-5 min? Bro, amazing!! Thank you so much!
The "Hi, I am hamburgers" 😂
finally understood it, thanks man
God bless you and the day you decided that you wanted to open a TH-cam channel man
Man you are just Awesome!!!!!!!!!!!
Brother you a saviour 😭😭
This is my seal. I have watched the entire video, understood it, and I can explain it in my own words, thus I have gained knowledge. This is my seal.
THANK YOU.
bro how do u have time to watch all these cartoons like in another video of yours i saw an example of pokemons and it was like that u know and follow pokemon till date, whereas i do coding all day like 10hrs per day but how do u have so much time 😭😭 btw love your teaching style u make everything look so easy thanks a lot man
will you be my mentor :), on my way to learn full stact(MERN) development.
since it is the same as writing the name of the object, is this keyword used in case there are nameless things? or so that you can use the same code for different objects since it automatically updates the object name in the method? Thanks so much bro, even if you don't answer, I know you've got work to do ❤
We need more React content :((
My Bro, why you are not making android development tutorial???????????☺☺☺☺☺☺☺☺☺
goat
I was playing around with the arrow function for 2 minute and gave up... Only for my Sensei to mention it doesn't work in the end
I still feel confused with those different ways of writing functions. What are the differences between them? why doesn't the arrow function refer to the object in which it was written when using 'this'?
yes bro we can't use this keyword in arrow function but we can use this keyword in setTimeout and setInterval function.
What does it think 'name' is if it's not 'this.name'?
EDIT: Oh is it because everything inside the function is inside the local scope of the function and NOT the local scope of the object? Therefore the object key-values aren't passed into the function without 'this'?
Thank you guys❤
Hi I am hamburgers
ohhhh now i know
this is keyword in jS??