>- see footer for list info -<
> > > I want to be able to set defaults for width/height in this
function in
> > > case my link doesn't contain these params. How do I specify this
in the
> > > function?
> >
> > if (arguments.length != 3) { ... }
>
> ... or ...
>
> if(!sWidth) { ... }
Or:
function foo(a, b) {
a = a || 123; // default a to 123
b = b || "b"; // default a to "b"
// ...
}
Or:
function foo(a, b) {
a = typeof(a) != 'undefined' ? a : 123; // default a to 123
b = typeof(b) != 'undefined' ? b : "b"; // default b to "b"
// ...
}
Ask 10 people, get 10 different answers :)
I find the top syntax looks the cleanest (a || b), but that doesn't work
for boolean values, or values that could be treated as boolean (anything
that evaluates as a boolean value will get 'defaulted') -- the same goes
for SteveD's solution (if (!arg) {...}).
In general, it's the 2nd style (using typeof) here's that's most
commonly used.
Here's some other people's opinions:
http://web-graphics.com/mtarchive/001709.php
http://experts.about.com/q/Javascript-1520/Default-parameter-value-funct
ion.htm
http://parentnode.org/javascript/default-arguments-in-javascript-functio
ns/
Etc...
Tim.
--
-------------------------------------------------------
TB: http://tim.bla.ir/ Tech: http://tech.badpen.com/
-------------------------------------------------------
RAWNET LTD - independent digital media agency
"We are big, we are funny and we are clever!"
http://www.rawnet.com/
-------------------------------------------------------
This message may contain information which is legally
privileged and/or confidential. If you are not the
intended recipient, you are hereby notified that any
unauthorised disclosure, copying, distribution or use
of this information is strictly prohibited. Such
notification notwithstanding, any comments, opinions,
information or conclusions expressed in this message
are those of the originator, not of rawnet limited,
unless otherwise explicitly and independently indicated
by an authorised representative of rawnet limited.
-------------------------------------------------------
_______________________________________________
For details on ALL mailing lists and for joining or leaving lists, go to
http://list.cfdeveloper.co.uk/mailman/listinfo
--
CFDeveloper Sponsors:-
>- Hosting provided by www.cfmxhosting.co.uk -<
>- Forum provided by www.fusetalk.com -<
>- DHTML Menus provided by www.APYCOM.com -<
>- Lists hosted by www.Gradwell.com -<
>- CFdeveloper is run by Russ Michaels, feel free to volunteer your help -<