How can I create argument defaults for a function?
How can I create argument defaults for a function?
I have this function (the purpose of the lines I included were to set defaults if the user forget to input something simply to prevent an error. I realize there is some lack of logic here):
addHSLink= function(elem, atts){
jQ= $(elem), atts= atts || {};
var props={ href: 'http://someurl.com', width:800, height:600}; // defaults
for(var p in atts) props[p]= atts[p];
//Some other code, using the defaults (if you do not override them)
// and any other properties you care to pass in the function call
}
Heh I see we posted at pretty much the same time. Thanks mrhoo. Do you think it's better to initialize the count for the for loop inside the loop's initialization params? I've been taught to initialize all instance variables in a single var line at the top of the function.
Bookmarks