Friday, March 16, 2012

Optional and have default value

Hi,

How can I set a parameter of a function optinal and have a default value?
In VB I do like this:
Function myFunction (Optional ByVal bExist as Boolean = False)

What's the equivalent in JScript?

--
Programming ASP.NET with VB.NET
Thank's (if you try to help me)
Hope this help you (if I try to help you)
rucajavascript doesn't require that all the parameters defined are passed in. It
is not compiled, and the interpreter doesn't care. So if there are 5
parameters defined, the caller can pass in 0, 1, 2, 3, 4 or 5 arguments in.
So in essence, they are all optional as far as the interpreter is concerned.

As far as default values, you would have to check if a particular argument
is null, and if it, manually assign it a value in your function to have the
effect of having a default value.

"ruca" <ruuca@.iol.pt> wrote in message
news:O3GNM4HIEHA.3968@.TK2MSFTNGP12.phx.gbl...
> Hi,
> How can I set a parameter of a function optinal and have a default value?
> In VB I do like this:
> Function myFunction (Optional ByVal bExist as Boolean = False)
> What's the equivalent in JScript?
>
> --
> Programming ASP.NET with VB.NET
> Thank's (if you try to help me)
> Hope this help you (if I try to help you)
> ruca
No direct equivalent. Here is a FAQ on args in JScript. It is not exactly
what you are looking for, but you should be able to adopt to your needs.

http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=42

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************** ********************
Think Outside the Box!
************************************************** ********************
"ruca" <ruuca@.iol.pt> wrote in message
news:O3GNM4HIEHA.3968@.TK2MSFTNGP12.phx.gbl...
> Hi,
> How can I set a parameter of a function optinal and have a default value?
> In VB I do like this:
> Function myFunction (Optional ByVal bExist as Boolean = False)
> What's the equivalent in JScript?
>
> --
> Programming ASP.NET with VB.NET
> Thank's (if you try to help me)
> Hope this help you (if I try to help you)
> ruca
By the way, I was talking about client side jscript...

"Marina" <someone@.nospam.com> wrote in message
news:O5I3nDJIEHA.3032@.TK2MSFTNGP09.phx.gbl...
> javascript doesn't require that all the parameters defined are passed in.
It
> is not compiled, and the interpreter doesn't care. So if there are 5
> parameters defined, the caller can pass in 0, 1, 2, 3, 4 or 5 arguments
in.
> So in essence, they are all optional as far as the interpreter is
concerned.
> As far as default values, you would have to check if a particular argument
> is null, and if it, manually assign it a value in your function to have
the
> effect of having a default value.
> "ruca" <ruuca@.iol.pt> wrote in message
> news:O3GNM4HIEHA.3968@.TK2MSFTNGP12.phx.gbl...
> > Hi,
> > How can I set a parameter of a function optinal and have a default
value?
> > In VB I do like this:
> > Function myFunction (Optional ByVal bExist as Boolean = False)
> > What's the equivalent in JScript?
> > --
> > Programming ASP.NET with VB.NET
> > Thank's (if you try to help me)
> > Hope this help you (if I try to help you)
> > ruca

0 comments:

Post a Comment