I've been struggling lately with understanding the best way to organize jQuery code. I asked one more question before, and I don't think I was specific enough ( found in this question here ).
My problem is that the richer you create the application, the faster your client side gets out of control. Consider this situation ...
//Let start some jQuery $(function() { var container = $("#inputContainer"); //Okay let list text fields that can be updated for(var i=0; i < 5; i++) { //okay let add an event for when a field changes $("<input/>").change(function() { //okay something changed, let update the server $.ajax({ success:function(data) { //Okay - no problem from the server... let update //the bindings on our input fields $.each(container.children(), function(j,w) { //YIKES!! We're deep in here now!! $(w).unbind().change(function() { //Then insanity starts... }); // end some function }); //end some loop } // what was this again? }); //ending something... not sure anymore }).appendTo(container); //input added to the page... logic WAY split apart }; //the first loop - whew! almost out! }); //The start of the code!!
Now this situation is not too far from impossibility. I'm not saying that this is the right way to do this, but it’s not uncommon to find several levels in the jQuery team and start wondering how much logic can be added before the screen starts to melt.
My question is: how do people manage this or organize to limit the complexity of their code?
I have listed how I do this in another post ...
javascript jquery code-organization
Hugoware Oct 30 '08 at 21:17 2008-10-30 21:17
source share