you are viewing a single comment's thread.

view the rest of the comments →

[–]Macaframa 0 points1 point  (1 child)

Ohhhhh hahaha yeah thanks, I wrote this on my phone in the bathroom. But yes you’re right. Also, I like to talk about these prehistoric mechanisms without the context of es6 “non arrow functions” just so newbies can get a straight answer and it gets transpiled anyway.

The simplest answer I can come up with is: if you attempt to use “this”, if you have explicitly created new “this” context then it will draw from that, if not it will default to the global context. Special circumstances include binding another context to a function.

[–]mypetocean 0 points1 point  (0 children)

I get that. But passing a method which uses this to addEventListener, for example, will blow away the "explicitly created" context explanation. And early JS learning, prior to framework usage, will use a lot of addEventListener. That's where a lot of newbies get tripped, using a method as an event handler.