Simple example of Javascript good programming style?
<p>I am struggling with Javascript. Most of my problems do not arise from lack of understanding of the language (well, that as well, but bear with me). Instead, the main issue is to understand what is good programming/code organization style.</p>

<p>For example, I need to have different entities (forms, text areas, tables, etc.) around in a page, and have them modified according to events, either user triggered or Ajax.</p>

<p>My first idea was to define one class for each entity, define methods on the prototype of these classes, then instantiate the classes binding them to specific HTML ids (either implicitly or when instantiated with new), and register handlers between events and method calls. In other words, kind of "QT-style". I soon realized that it's not trivial. You cannot register object methods directly as callbacks, you have to wrap them in a closure, etc... </p>

<p>Another idea I had was to declare just a bunch of callback functions, no objects, and each callback operates on global variables and on the DOM. Quick and dirty, no fuss. It's like your page is just a big object whose events are handled internally. </p>

<p>Every solution I could think of left me with the sensation that I was drastically misusing the tool. In the end, I don't feel comfortable because I saw very few javascript code in my programming experience, and it's very different from all the languages I have experience with. Peeking into the first stuff I download it's guaranteed to be a waste of time, as it is compressed and/or obfuscated and/or not "up to date" with the current "good javascript practices", so I am asking you a simple, powerful and clean web page plus its associated javascript code to get quickly into a proper programming/code layout style.</p>

<p>(I'm using jQuery, but my question is independent from that. Nevertheless, an example using jQuery would be preferred).</p>
