I don't understand 'this' RT if you don't understand either....we need answers!!
@JavaScriptCoff1 Hardest concept of JS imo. I didn't get it until I was fully comfy with OOP... Good news is that modern JS practices is this-less
@JavaScriptCoff1 Javascript The Good Parts has good explanations. But I saw some tweets from @IrenSayWhen with tl;dr on how this works depending on how you invoke the function
@JavaScriptCoff1 youtu.be/Bv_5Zv5c-Ts Maybe this will help?
@JavaScriptCoff1 First get your head around scope. Learn functions scope. Once you duly understand scope. Learning about *this* will be a lot easier. Dealing with functions *this* is the scope within the function. This chs he's when using arrow functions.
@JavaScriptCoff1 this" can reference a different object depending on where/how it's used. In class-based components "this" refers to the "instance" of the object that is created when you use the new keyword. In other words, it's the object you are currently working in.
@JavaScriptCoff1 Some videos to help along (i love YouTube coding explanation videos, as you know) — • youtube.com/watch?v=NV9sHL… • youtube.com/watch?v=AOSYY1… • youtube.com/watch?v=GhbhD1… • youtube.com/watch?v=AYVYxe… (when/how to use call(), add() & bind() with `this`) ...hope all this helps! 4/done.
@JavaScriptCoff1 (cont'd.) ...to declare your vars & functions, then those have BLOCK Scope, and their `this` in a browser window in the Window Object itself, which, unless you know EXACTLY where your code is at when it runs and how to get where you want to go, is *not* what you want. ... 3/
@JavaScriptCoff1 (cont'd.) ...so if you're accessing `record.name,` the `this` is `record.` in a browser window DOM tree, it's whatever is the parrent object of the DOM node you were in when the JS ran. • if you use the more modern `const,` `let` or arrow functions `() => {}` ... 2/
@JavaScriptCoff1 here's the main thing you need to understand, and again, it has to do with JS Scope & Hoisting - • if you declare vars & functions with `var` & `function` keywords, their `this` is what is directly to the LEFT of the Object dot. ... 1/
@JavaScriptCoff1 After rewatching tutorials and reading quite a bit.. I think I can say I understand 'this' by a descent amount