I am using the following coding pattern:
function submit() {
function submitModalDone() {
// do something
}
function submitModalFail() {
// do something
}
$.ajax(
{
url: "xxx"
})
.done(submitModalDone)
.fail(submitModalFail);
}
I placed the submitModalDone and submitModalFail inside the submit function as these are only called from the $.ajax.
However is it a good idea to just add my code as is to the end of the function and after all of the child functions. Is there a design pattern that would be a better fit for this? It seems strange that the $.ajax code and other code just sits there outside any container.
I think that’s a decent, descriptive pattern.
You might want to structure it like this, however:
This avoids creating
submitModalDoneandsubmitModalFailevery timesubmitis called.