jquery - Way to check a bunch of parameters if they are set or not in JavaScript -


so, happens me quite frequently, here's latest one:

  var generic_error = function(title,msg){         if(!title){ title= 'oops!'; }         if(!msg) { msg = 'something must have gone wrong, no worries we\'re working on it!'; }         $.fancybox(         {             content:'\                 <div class="error_alert">\                     <h2>'+title+'</h2>\                     <p>'+msg+'\                 </div>'         });     } 

is there cleaner way check params title , msg above , or set them optional or define defaults in function how php example? have 10 options , if(!var){var='defaults'} x 10 icky...

slightly shorter equivalent you're doing use "||" aka "or" aka "the default operator".

title = title || 'oops!';  msg = msg || 'something must have gone wrong, no worries we\'re working on it!'; 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -