Re: multiple parameters in function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Thomas 'PointedEars' Lahn

    Re: multiple parameters in function

    jodleren wrote:
    On Jul 2, 12:04 pm, jodleren <sonn...@hot.ee wrote:
    >I want to pass one or two parameters to a function, such as
    >>
    > function OpenDirSel(inpu t, 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(inpu t, 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(in put);
    }

    or

    function openDirSel(inpu t)
    {
    /*
    * Gauntlet to return if the argument value is a false-value;
    * no *named* second argument, so we use the `arguments' object.
    */
    if (!arguments[1]) return null;

    window.alert(in put);
    }

    and then

    if (!openDirSel("B OO!"))
    {
    // DEBUG: `undefined' converts to `false'
    window.alert("o penDirSel: Invalid second argument!");
    }
    Like in
    <input name="btn_dir1" type="button" value=" ... "
    onclick="OpenDi rSel(dir1.value , 'test');">
    It would not work because `dir1' did not refer to an object. ISTM you were
    looking for `this' instead, to refer to the object handling the event.

    Or your markup could be not Valid, so there was no script code to execute:
    <http://validator.w3.or g/>


    PointedEars
    --
    Anyone who slaps a 'this page is best viewed with Browser X' label on
    a Web page appears to be yearning for the bad old days, before the Web,
    when you had very little chance of reading a document written on another
    computer, another word processor, or another network. -- Tim Berners-Lee
  • Thomas 'PointedEars' Lahn

    #2
    Re: multiple parameters in function

    Thomas 'PointedEars' Lahn wrote:
    jodleren wrote:
    >On Jul 2, 12:04 pm, jodleren <sonn...@hot.ee wrote:
    >>I want to pass one or two parameters to a function, such as
    >>>
    >> function OpenDirSel(inpu t, 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(inpu t, 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(in put);
    }
    >
    [...]
    and then
    >
    if (!openDirSel("B OO!"))
    {
    // DEBUG: `undefined' converts to `false'
    window.alert("o penDirSel: Invalid second argument!");
    }
    Hmmm, to explain better, I should have returned `true' if all necessary
    arguments were passed:

    function openDirSel(inpu t, user)
    {
    /*
    * Gauntlet to return if the argument value is a false-value;
    * or you could throw an exception etc.
    */
    if (!user) return false;

    window.alert(in put);
    return true;
    }


    PointedEars
    --
    var bugRiddenCrashP ronePieceOfJunk = (
    navigator.userA gent.indexOf('M SIE 5') != -1
    && navigator.userA gent.indexOf('M ac') != -1
    ) // Plone, register_functi on.js:16

    Comment

    Working...