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

The reason why some frameworks roll out custom object systems is because they try to make JavaScript look like a language with classes, "this" semantics isn't what's driving them. In a language with classes developers are used to "this" being an instance of the current class, and this expectation creates a consfusion in JavaScript. If you don't look at it through the prism of classes, the rule for "this" is pretty simple: "this" is the receiver. Create a function, apply it to any object, and that object will be the receiver available as "this". It's that simple. Now the only confusion left is who's the receiver. In "foo.bar()" like cases it's obvious, and the only remaining case (if you don't count the discouraged "with" statement) is "bar()" which calls a function on the global object (like in Python).



You've left out event handlers, which are another case in which `this` can get confusing.




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

Search: