There is a time table in my web page, I want the user to be able to:
- click on a cell and see which courses is at this time
- click on an arrow and change de week
How should I build my JavaScript classes?
-
I don’t use classes and I interact with the dom as we can see in 99% of the JavaScript code in the world
-
I create one class TimeTable that will observe event (such as click on a cell), make ajaxcall, change the cell content etc…
-
I try to make things perfect:
-
A) a class that will wrap all the html stuff (changing style/ content)
-
B) a class that will wrap my ajax call
-
C) a class that will wrap my business logic
-
D) a class to make all those things work together, observe the event from An and call C or D and then call A to change the UI.
-
IMHO the last solution is the best it’s kind of a MVC (An is the View, D is the Controller, and the two others are the models). But it seems like one of the less easy to implement.
Did you ever use this kind of technique? Is there any related blog / documentation to help me? Do you think it’s relevant? There is something better?
Try backbonejs. It’s light weight MVC with full control over the view and html system.
The design decisions of the application structure are varied and really should be upto you if you want to achieve your own functionality.