I want my function to have one parameter, namely boolParam, which has
a default value of TRUE;
I try to design my function the other way round. If a boolean parameter is
optional, make the default false. Then you can easily handle the default
case:
function f(b) {
b = b || false;
}
or
function f(b) {
b = !!b;
}
or
function f(b) {
if (b) {}
}
The same goes with other types of optional parameters, but this can be
much harder and even impossible (or ridiculous). If reasonable, let a
function behave the same when omitting an optional parameter and passing
in a falsy value.
Matt
--
Follow me on twitter.com/gweax
--
To view archived discussions from the original JSMentors Mailman list:
http://www.mail-archive.com/[email protected]/
To search via a non-Google archive, visit here:
http://www.mail-archive.com/[email protected]/
To unsubscribe from this group, send email to
[email protected]