How to structure Javascript programs in complex web applications?
Posted
by mixedpickles
on Stack Overflow
See other posts from Stack Overflow
or by mixedpickles
Published on 2010-03-09T09:25:52Z
Indexed on
2010/03/09
9:36 UTC
Read the original article
Hit count: 137
Hi there. I have a problem, which is not easily described. I'm writing a web application that makes heavy usage of jquery and ajax calls. Now I don't have experience in designing the architecture for javascript programms, but I realize that my program has not a good structure. I think I have to many identifiers referring to the same (at least more or less) thing.
Let's have an exemplary look at an arbitrary UI widget:
- The eventhandlers use DOM elements as parameters. The DOM element represents a widget in the browser.
- A lot of times I use jQuery objects (I think they are basically a wrapper around DOM elements) to do something with the widget. Sometimes they are used transiently, sometimes they are stored in a variable for later purposes.
- The ajax function calls use strings identifiers for these widgets. They are processed server side.
- Beside that I have a widget class whose instances represents a widget. It is instantiated through the new operator.
Now I have somehow four different object identifiers for the same thing, which needs to be kept in sync until the page is loaded anew. This seems not to be a good thing. Any advice?
© Stack Overflow or respective owner