JavaScript this Keyword
🔥Get the COMPLETE course (83% OFF – LIMITED TIME ONLY): http://bit.ly/2M1sp4B
Subscribe for more videos:
https://www.youtube.com/channel/UCWv7vMbMWH4-V0ZXdmDpPBA?sub_confirmation=1
Want to learn more from me? Check out my blog and courses:
http://programmingwithmosh.com
https://www.facebook.com/programmingwithmosh/
Tweets by moshhamedani
Original source
37 responses to “JavaScript this Keyword”
Thanks. Watch it using 0.75x pace and Thank me later
Thank u a lot Mosh. That was a very clear and good explanation. Helped me a lot with something that was quite unclear to me up to this point 🙂
Awesome explanation. Thanks!
Thank you a bunch
It helped me a lot
You are a very good teacher. now i understand the basics of this thanks to you. I love your Javascript videos I've learned a lot of things thanks to you. Thanks a lot for sharing your knowledges.
Thanks. A very easy to understand and abundantly clear video.
Very nice Mosh. Now why there are dozens of complicated articles that doesnt make sense? I read today abou five long articles about call(), apply(), bind() and this but was more and more confused. They maybe get it right but teach it wrong … in this short video I had two big insights – it clicked all together. Thx.
>criticizes others for their teaching methods
>blazes pass the material at the speed of light
🙄
My saviour!
I am getting brain fuck from "this"
Urgent Question: I am fairly comfortable with JavaScript. I know ES6 basics as well useful for React developers.
I have an interview in 4-5 days and wanna know should I invest my time in Mosh's JavaScript YouTube video or the course?
Is it beneficial for a JavaScript focussed interview with tech giants here in the US?
awesome explanation .. Thanks
Great
Honestly, this makes so much sense to me. When people were telling me the 'this' in JavaScript is complicated I was worried that I would struggle to learn it but it makes so much sense if you stick to the rules for methods, functions, and constructor functions.
At first i didn't understand this, then my brain got fucked by the explanation but afterwards i understood, as an overall it was an incredible explanation you just got a let it sink.
Damet garm!
That was a good short explanation. Thanks Mosh.
You can also do like this:
const video = {
title: 'a',
tags: ['a','b','c'],
showTags(){
this.tags.forEach((tag) => {
console.log(this.title, tag);
});
}
};
video.showTags();
the => does not create a "this" context, it gets the "this" context from the enclosing scope, which in this case, is the video object itself. Nice lesson, I learned a lot.
Great explanation! Thanks.
Most clear explanation ever! thanks
Super simple. Many Thanks 🙂
Awesome Explanation ! Finally I got "This" !
i have a doubt though in 2:01 Mosh says that stop is a method in the video object but isn't it actually outside the video obje t
This is complicated
Simple and useful! Thanks for your classes 😀
Is there any specific reason why you don't us name-value pair for the method play?
nice!
Wow, I watched only the first minute and it makes so much sense now than trying to read articles about it!
Great explanation!
Link to the next video?
I rarely make comments on YouTube, I just want say THANK YOU, this is by far the best explanation for the "this" keyword I have found!
At 3:08 in constructor function we are neither calling the object nor the constant V …so how we are getting that object in console ?? i am kinda confused …pls elaborate sir…
great explanation, and by the way, can I know what IDE are you using?
best explanation ever!!
,you have such a bieautiful explanation man ,please keep it up
tl;dr:
case 1:
`this` in an object method — referencing the object.
case 2:
`this` in a regular function — referencing `window` (`global` in node.js)
case 3 – a special case inferred from case 1:
function Video() {console.log(this);}
new Video;
referencing a new `Video` object, because `new` creates an empty object `{ }` and `Video` serves as a constructor method of the object.
case 4 – a special case inferred from case 2:
`this` in a regular function in an obj method — referencing `window` because `this` is in a regular function.
case 1 at 1:00
case 2 at 2:13
case 3 at 2:33
case 4 at 4:35
Note: all the four cases above are based on the assumption that nothing is tampered with by things like `call`, `apply` and `bind`.
Nice, you did an excellent job here, congrats!
I was lucky I learned OOP basics during a college course, most of the teaching material available for self learning is confusing.