私は最近、jQuery コードを整理する最善の方法を理解するのに苦労しています。私は以前に別の質問をしましたが、私は十分に具体的ではなかったと思います (この質問はこちらにあります)。
私の問題は、アプリケーションをリッチにすればするほど、クライアント側が制御不能になるのが早くなることです。この状況を考えてみてください...
//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!!
現在、この状況は不可能からそう遠くありません。これが正しい方法だと言っているわけではありませんが、jQuery コマンドのいくつかのレベルまで下がって、画面が溶け始める前にロジックをどれだけ追加できるか疑問に思うことは珍しくありません。
私の質問は、人々はこれをどのように管理したり、コードの複雑さを制限するために組織したりしているのですか?