Nobody likes to be called a dummy by a dummy.

optional arguments to a function in javascript

Is this possible?  Can I specify a default value a la:

function foo(mode = 'input', teeth = 'yellow') {
  do some stuff
}

?
Permalink Send private email muppet 
January 27th, 2006 11:17am
Nope, you want python.

:-)
Permalink Send private email Simon Lucy 
January 27th, 2006 11:18am
well I can do it in perl and PHP just fine, Simon, so I don't need python.  I was just curious if javascript allowed it.
Permalink Send private email muppet 
January 27th, 2006 11:19am
Arguments are optional - callers can call with less or more parameters and there will be no errors, but the undefined parameters will be...undefined. So you could set the defaults simply by checking if it's undefined.

Alternately look at the arguments array.
Permalink Send private email Dennis Forbes 
January 27th, 2006 11:20am
That's good enough.
Permalink Send private email muppet 
January 27th, 2006 11:21am

This topic is archived. No further replies will be accepted.

Other topics: January, 2006 Other topics: January, 2006 Recent topics Recent topics