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 to this:
consto={f:function(){console.log(this);}};o.f();// prints o, no problems!constg=o.f;// passed around the function instance, this could be passing to an event handler or some thingg();// prints window, oops.
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 that this is determine when the function is called and how the function is called, in the example here, this changed because I no longer called f() with o behind the dot operator. So it defaults to the global object.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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.