JavaScript this Keyword Explained Simply
Вставка
- Опубліковано 9 лют 2022
- In most cases, the value of 'this' is determined by how a function is called. 'this' usually refers to the object that is calling the current function. If a function, foo(), is called from the global scope ("foo()"), then 'this' will refer to the global object - the Window object. But if foo() is called from inside the scope of another object ("devsage.foo()"), then 'this' will refer to the object that is calling foo() - which is the 'devsage' object. Arrow functions don't provide their own 'this' binding so it inherits the 'this' value of the enclosing function.
📚Materials/References:
MDN Web Docs: developer.mozilla.org/en-US/d...
🌎 Find Me Here:
Twitter: / realdevsage
Discord: / discord
Ebooks: payhip.com/devsage
Merch: cottonbureau.com/people/devsage
💙 Twitter: twitter.com/realDevSage
📙 Ebooks: payhip.com/devsage
💥 Discord: discord.gg/BP8wPv6raA
👕 Merch: cottonbureau.com/people/devsage
Seriously great explanation! Came here for more clarification on it after The Odin Project lesson Objects and Object Constructors
Same haha
'This' references to the object that calling the function.
This simple sentence cleared my mind after reading a lot of stuff about 'this'. Your explanation is amazing!!
Amazing explanation, much more concise than articles I've read.
Glad it helped!
Appreciate all your useful vids. They've substantially benefited me in the first couple months I started out.
I've been struggling to fully comprehend this; your video really helped me out. Looking forward to checking out more of your vids ;)
Finally someone that doesn't speak overly fast
Thanks a lot. One of the clearest explanations of `this`. 🔥
No problem, Aruna!
Very clean explanation, thanks for that!
No problem!
i really want to say thank you because your simple explanation made me get it finally
Very clear explanation ..
Very nicely explained. Thanks
No problem!
Bro, that arrow function confused me while reading an article T - T. Thanks man!
Happy to help!
Great explanation, thank you!
Great explanation, thanks!
Very good and instructive explanation
best video on this topic! ty.
No problem!
you are a legend
Thanks!
a big thumb up for you, thank you!
was very helpful, thanks ..
You're welcome!
best tutorial on "this" subject
Thanks!
So, could we say that using inline functions with the `this` keyword is discouraged (bad practice) since it would require it being nested within a normal function?
Meaning that instead of using an inline and nesting it, It's better to simply just use a normal function? Please correct me if I am mistaken! :)
Correct.
Is it possible to import any module without writing the module type and export it
this is awesome
Thank you
I subscribed because i was able to understand "this"
Thanks!
9:53 Could you just use an arrow function with the forEach method/function to solve the "this" problem?
Yes!
on forEach (8:02) when this refers to window object why dont we use arrow function for ex: this.hobbies.forEach((hobby)=>{ ( console.log( this.firstName )} ));
You can, i guess he just wanted us to learn how to fix it without changing the callback function type.
Right , but its more interesting to do that way for the sake of concept and learning isnt ?