javascript - De-Anonymizing an Anonymous Function in jQuery -


this quite simple problem, it's causing me scratch head, i'm posting here.

i have jquery in following form:

if (jquery('.searchregions:checked').length == 0) {   jquery('.searchregions').each(function(){          //code      });  } else {  jquery('.searchregions:checked').each(function(){          //the same code           });  } 

obviously seems ridiculous repeat big block of code inside each of these functions. when tried name , move function, seemed break down - perhaps because of issues scope and/or jquery(this) inside function no longer referring same object?

can me posting general idea of code should like? (or other optimisings or recastings make work appreciated!)

you can define function , use name:

function somehandler(event) {   // code code code }  jquery('.searchregions').each(somehandler); 

note when refer function name, don't include "()".


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -