Hacker News new | past | comments | ask | show | jobs | submit login

The behavior of 'this' is from DOM bindings and not from the language per se. Javascript can set 'this' of any calling context to any object with 'apply' or 'call'. The convention for on* handlers is that 'this' is set to the DOM element when the handlers are called. I only learned to appreciate this, when I wrote my own little JS DOM framework a la JQuery or Dojo.



I believe actually that 'this' points to the global object.

So if there is no obvious thing for this to point at, it'll point at the global object. Its just implementation detail that in browsers it points to the window object.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: