calling a optional parameter function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • (-: Dan :-)

    calling a optional parameter function

    hi everybody

    suppose I have a function in a DLL

    function F1(var1, var2, var3)

    where var2 and var3 are optional parameter with default value (for
    exsample "-1")

    I create a new instance of my class and then I call F1.
    In VBS I can call function in 4 ways:
    1. F1(1)
    2. F1(1,2)
    3. F1(1,2,3)
    4. F1(1, ,3)

    but in js the #4 generate error.

    Can I call 4th way?

    tnx Daniele

  • rf

    #2
    Re: calling a optional parameter function


    "(-: Dan :-)" <nntlodo@tiscal inet.it> wrote in message
    news:3F86A2A0.D C175F1C@tiscali net.it...[color=blue]
    > hi everybody
    >
    > suppose I have a function in a DLL
    >
    > function F1(var1, var2, var3)
    >
    > where var2 and var3 are optional parameter with default value (for
    > exsample "-1")
    >
    > I create a new instance of my class and then I call F1.
    > In VBS I can call function in 4 ways:
    > 1. F1(1)
    > 2. F1(1,2)
    > 3. F1(1,2,3)
    > 4. F1(1, ,3)
    >
    > but in js the #4 generate error.
    >
    > Can I call 4th way?[/color]

    No.

    Optional means from here on. You can not omit a parameter.

    Cheers
    Richard.


    Comment

    • Lasse Reichstein Nielsen

      #3
      Re: calling a optional parameter function

      "(-: Dan :-)" <nntlodo@tiscal inet.it> writes:
      [color=blue]
      > 4. F1(1, ,3)[/color]
      [color=blue]
      > Can I call 4th way?[/color]

      Try
      F1(1,undefined, 3)

      In Javascript, you can only omit arguments from a point. The effect
      is that the parameter gets the value "undefined" , just as if you had
      passed it as a value.

      /L
      --
      Lasse Reichstein Nielsen - lrn@hotpop.com
      Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
      'Faith without judgement merely degrades the spirit divine.'

      Comment

      • Lee

        #4
        Re: calling a optional parameter function

        Lasse Reichstein Nielsen said:[color=blue]
        >
        >"(-: Dan :-)" <nntlodo@tiscal inet.it> writes:
        >[color=green]
        >> 4. F1(1, ,3)[/color]
        >[color=green]
        >> Can I call 4th way?[/color]
        >
        >Try
        > F1(1,undefined, 3)[/color]

        It would seem to be cleaner to supply the default value
        as found in the documentation for that function:

        F1(1,-1,3);

        Comment

        • Dr John Stockton

          #5
          Re: calling a optional parameter function

          JRS: In article <bm6iuf01l1p@dr n.newsguy.com>, seen in
          news:comp.lang. javascript, Lee <REM0VElbspamtr ap@cox.net> posted at Fri,
          10 Oct 2003 08:23:59 :-[color=blue]
          >Lasse Reichstein Nielsen said:[color=green]
          >>"(-: Dan :-)" <nntlodo@tiscal inet.it> writes:
          >>[color=darkred]
          >>> 4. F1(1, ,3)[/color]
          >>[color=darkred]
          >>> Can I call 4th way?[/color]
          >>
          >>Try
          >> F1(1,undefined, 3)[/color]
          >
          >It would seem to be cleaner to supply the default value
          >as found in the documentation for that function:
          >
          > F1(1,-1,3);[/color]

          Since F1 may be variable, perhaps supplied as a function parameter, the
          actual value used for an undefined parameter may vary. Moreover, I have
          a case where undefined actually means leaving out a bit of processing.
          Zero would have the same effect, but waste time.

          If an undefined value is needed, then define one. I believe that var U
          does this in a satisfactory manner, though a longer name might be
          preferred.

          --
          © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
          <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
          <URL:http://www.merlyn.demo n.co.uk/js-index.htm> JS maths, dates, sources.
          <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.

          Comment

          • (-: Dan :-)

            #6
            Re: calling a optional parameter function

            >[color=blue]
            >
            > Since F1 may be variable, perhaps supplied as a function parameter, the
            > actual value used for an undefined parameter may vary. Moreover, I have
            > a case where undefined actually means leaving out a bit of processing.
            > Zero would have the same effect, but waste time.
            >
            > If an undefined value is needed, then define one. I believe that var U
            > does this in a satisfactory manner, though a longer name might be
            > preferred.
            >[/color]

            I can't traslate correctly...... ... :-((

            Comment

            • Lasse Reichstein Nielsen

              #7
              Re: calling a optional parameter function

              Lee <REM0VElbspamtr ap@cox.net> writes:
              [color=blue]
              > It would seem to be cleaner to supply the default value
              > as found in the documentation for that function:
              >
              > F1(1,-1,3);[/color]

              If you know the default value, and if there is one.

              The default value for any omitted argument in Javascript *is*
              undefined. However, you can only omit at the end of the argument list,
              not in the middle.

              A function can distinguish between
              F1(1)
              and
              F1(1,undefined)
              only by looking at arguments.lengt h, or by checking
              '1' in arguments
              (although it seems to be bugged in Opera)

              /L
              --
              Lasse Reichstein Nielsen - lrn@hotpop.com
              Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
              'Faith without judgement merely degrades the spirit divine.'

              Comment

              • Lasse Reichstein Nielsen

                #8
                Re: calling a optional parameter function

                Dr John Stockton <spam@merlyn.de mon.co.uk> writes:
                [color=blue]
                > If an undefined value is needed, then define one. I believe that var U
                > does this in a satisfactory manner, though a longer name might be
                > preferred.[/color]

                In ECMAScript, "undefined" is a global variable holding the undefined
                value.
                If you target non-ECMAScript browsers, you can ensure that it is defined
                with a sigle, otherwise harmless, line:
                window.undefine d = window.undefine d;
                It has the advantage of working in any scope. If you know you are at
                the root scope, you can just use
                var undefined;

                /L
                --
                Lasse Reichstein Nielsen - lrn@hotpop.com
                Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
                'Faith without judgement merely degrades the spirit divine.'

                Comment

                Working...