On Fri, Oct 21, 2011 at 5:18 PM, HankyPanky <[email protected]> wrote:
> I want my function to have one parameter, namely boolParam, which has
> a default value of TRUE;
> In the first place, it seems that the following snippet will do, but
> it's absolutely wrong and boolParam will always set to TRUE even if a
> false value is passed to the function;
>
> What's your solution to this using this pattern?

The only true way to check this is to check the "magic" arguments
object. That tells you how many parameters were actually passed on.

function f(a){
  if (arguments.length == 0) a = true;
  return a;
}
f(false) === false
f(undefined) === false
f() === true

- peter

-- 
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]

Reply via email to