Últimamente he tenido problemas para comprender la mejor manera de organizar el código jQuery. Hice otra pregunta antes y no creo que fuera lo suficientemente específica (found in this question here).jQuery y "Código organizado"
Mi problema es que cuanto más rico que realice una solicitud, más rápido del lado del cliente se sale de control. Considere esta situación ...
//Let's start some jQuery
$(function() {
var container = $("#inputContainer");
//Okay let's list text fields that can be updated
for(var i=0; i < 5; i++) {
//okay let's add an event for when a field changes
$("<input/>").change(function() {
//okay something changed, let's update the server
$.ajax({
success:function(data) {
//Okay - no problem from the server... let's 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!!
Ahora esta situación no está demasiado lejos de ser imposible. No estoy diciendo que esta sea la manera correcta de hacerlo, pero no es raro encontrar varios niveles en un comando jQuery y comenzar a preguntar cuánto más lógica puede agregar antes de que la pantalla comience a derretirse.
Mi pregunta es ¿cómo se gestionan las personas o la organización de este para limitar la complejidad de su código?
I listed how I'm doing it in my other post ...
.changed (... debe ser .Cambiar (... –
Tienes razón, lo hice de memoria ... que no es lo mejor para mí ... – Hugoware
¿Podrías editar la publicación y corregirla, entonces? Me dio confusión mientras estaba leyendo una de las respuestas. – montrealist