I created a popup function and recently changed the format from this:
createPopUp('My Popup',600,200);
to this method:
createPopUp({ title: 'My Popup', width: 600, height: 200 });
I only want to use the values if they exist, so I am currently doing this:
function createPopUp(config){
if (typeof config.title != 'undefined'){
var theTitle = title;
} else {
var theTitle = 'Untitled';
}
}
However this seems very messy so I have been looking for a more efficient way of checking for incoming parameters or setting default values and a nudge in the right direction would be much appreciated.
You can extend a default set of properties like this:
jQuery has a handy
$.extend()for this purpose, but you didn’t tag your post as such.