The keyword this in Javascript can be a little slippery to wrap your had around at first.
TL;DR When you refer to this in the global context, it ...
For further actions, you may consider blocking this person and/or reporting abuse
You didn't really touch the tricky parts of
this. Like for example, what happens when you try to pass around a function that refers tothis:The main problem with
thisisn't that you need to pass it around in a parameter or that you might accidentally define things outside the scope.The main problem with
thisis thatthisis determine when the function is called and how the function is called, in the example here,thischanged because I no longer calledf()withobehind the dot operator. So it defaults to the global object.And then, for a most advanced part, one could talk about arrow functions special rules and the
bindfunction.This doesn't make any sense. The comments have hearts, but the content doesn't. (See what I did there?)
Nice one Rachel. Just incase anyone is also curious about the "This" keyword in java,
why not check the link...... medium.com/java-for-absolute-dummi...
Excellent! Cheers :)
Thanks! Your article actually cleared this topic right up for me.
Helpful! I tutor students learning to code and will save 'this' 😉 post and use liberally. Well-done and fun to read!
The most important thing to understand about this is that it refers to the caller from the call stack. Not to be confused with lexical scope.