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() {
...
}
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() {
...
}
Is this the correct way to split out code to smaller functions?
Not really, since your check_values
function is now part of the global window
object. 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:
$(document).ready(function(){
function check_values() {
...
}
$("form#create_form").submit(function() {
...
var is_okay = check_values(...);
...
});
});