Is this the correct way to split out code to smaller functions?
$(document).ready(function(){
$("form#create_form").submit(function() {
...
var is_okay = check_values(...);
...
});
});
function check_values() {
...
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Not really, since your
check_valuesfunction is now part of the globalwindowobject. Leaking objects into the global space is badm, mkay?Unfortunately there are so many ways that it could be done that it’s hard to know where to start.
If your code is small it would be best just to leave it all within the closure inside your
$(document).ready()function: