I am struggling with Javascript. Most of my problems do not arise due to a lack of understanding of the language (well, it is also, but carry me). Instead, the main problem is to understand what a good programming / code style is.
For example, I need to have different objects (forms, text areas, tables, etc.) on the page and change them according to events triggered by the user or Ajax.
My first idea was to define one class for each entity, define methods in the prototype of these classes, and then create classes that bind them to certain HTML identifiers (either implicitly or when creating instances with new ones), and registration handlers between events and method calls. In other words, this is a "QT style." I soon realized that this was not trivial. You cannot register object methods directly as callbacks, you must wrap them in closure, etc.
Another idea I had was to declare only a bunch of callback functions, no objects, and each callback works with global variables and the DOM. Fast and dirty, no fuss. It looks like your page is just a big object, whose events are handled internally.
Every decision I could think of left me with the feeling that I was resolutely abusing the instrument. In the end, I donโt feel comfortable because I have seen very little javascript code in my programming experience, and it is very different from all the languages โโwith which I have experience. Looking into the first material I download, it is guaranteed to be a waste of time, as it is compressed and / or tangled and / or not โupdatedโ with the current โgood javascript practices,โ so I ask you for a simple, powerful and clean web page plus its associated javascript code to quickly fit into the correct code / code layout style.
(I use jQuery, but my question is not dependent on this. However, it is preferable to use the jQuery example).
javascript
Stefano borini
source share