Using closures in a different way
this references can often be totally unrelated to the lexical scope of a function. To work around that we often see tricks like:
var that = this;
this. Sounds crazy? Let’s see.
jQuery makes it really easy to work with the DOM and other browser APIs. Almost too easy. Having the almighty
$ available to you at all times can lead to an architectural style that I refer to as “jQuery soup.”
A jQuery soup codebase is one where adhoc references to
$ appear everywhere. AJAX calls and DOM manipulations are intermingled alongside application logic and business rules.
$ is essentially mutating a big bag of shared global state. That means that whenever you want to modify or extend that part of the app you need to carefully maintain a large mental model of every DOM interaction in your head. That’s really hard to do, and very much prone to error.