Topic awaiting preservation: simple javascript function question |
|
---|---|
Author | Thread |
Paranoid (IV) Inmate From: Seattle, WA, USA |
posted 03-14-2002 20:22
ok so I have a javascript function. It does a lot of different things, and for one of this things I want to be able to include another argument, but none of the others need it, so it would be a hassle to have it in every call of the function, so I was wondering if there was a way I could make the argument optional. I know there's ways to do this in other scripting languages, but I've never come across it in javascript. Does it exist, and if so how would I accomplish this? |
Paranoid (IV) Inmate From: 127.0.0.1 |
posted 03-14-2002 21:12 |
Lunatic (VI) Mad Scientist From: Massachusetts, USA |
posted 03-14-2002 21:16
In JavaScript, all arguments are automatically optional. If an argument isn't specified, it will have the undefined value inside the function. For instance, the following function |
Paranoid (IV) Inmate From: Seattle, WA, USA |
posted 03-14-2002 21:17
Thanks Slime, |
Maniac (V) Mad Scientist From: New California |
posted 03-16-2002 05:21 |
Lunatic (VI) Mad Scientist From: Massachusetts, USA |
posted 03-16-2002 05:41
On the other hand, that enables it to have things like the eval() function, which are amazingly overused... and it's slower too; much slower than a real, compiled, language. So, advantages and disadvantages, really. Compiled languages tend to have more low-level things that give you ways of getting around the lack of an eval() function or the [] operator for indirection. |