I've been reading up on anonymous javascript functions and have a general question about using them with event listeners via jquery.
I have the following event listener that will do some stuff upon the submission of a form.
if(sky === 'blue') {
$('#my-form').on('submit', function(){
//do some stuff
$('#my-div').show();
})
}
Would it make any difference (i.e., pros & cons, things that could go wrong, etc.) if I were to declare it as-is in my javascript file or should I be wrapping it in an anonymous function like so
$(function() {
if(sky === 'blue') {
//do my stuff
}
Any input is appreciated, thanks!