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
this
isn'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
this
is thatthis
is determine when the function is called and how the function is called, in the example here,this
changed because I no longer calledf()
witho
behind 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
bind
function.Helpful! I tutor students learning to code and will save 'this' 😉 post and use liberally. Well-done and fun to read!
Excellent! Cheers :)
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...
Thanks! Your article actually cleared this topic right up for me.
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.