![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
|
On Jul 2, 12:04 pm, jodleren <sonn... (AT) hot (DOT) ee> wrote: I want to pass one or two parameters to a function, such as function OpenDirSel(input, user) { } The point: it does not work with 2 parameters, why? Is there a way, that I can make the 2nd parameter optional? |
|
Like in input name="btn_dir1" type="button" value=" ... " onclick="OpenDirSel(dir1.value, 'test');" |
#2
| |||
| |||
|
|
jodleren wrote: On Jul 2, 12:04 pm, jodleren <sonn... (AT) hot (DOT) ee> wrote: I want to pass one or two parameters to a function, such as function OpenDirSel(input, user) { } The point: it does not work with 2 parameters, why? Is there a way, that I can make the 2nd parameter optional? ECMAScript functions do not have arity (a fixed number of arguments that they take). This means *all* arguments are optional on call. Whether they are also implemented as being optional, depends on you/the function's developer. For example: function openDirSel(input, user) { /* * Gauntlet to return if the argument value is a false-value; * or you could throw an exception etc. */ if (!user) return null; window.alert(input); } [...] and then if (!openDirSel("BOO!")) { // DEBUG: `undefined' converts to `false' window.alert("openDirSel: Invalid second argument!"); } |
![]() |
| Thread Tools | |
| Display Modes | |
| |