Omitting param-s 
Author Message
 Omitting param-s

Is there a way to omit optional parameters in JScript as in VBScript?
Like "func(,,,par)"


Mon, 06 Sep 2004 15:48:52 GMT  
 Omitting param-s
I think you can only use optional parameters after the defined ones.

So a function like funct(par) {}
can be called like funct(par,arg2,arg3,etc)



Quote:
> Is there a way to omit optional parameters in JScript as in VBScript?
> Like "func(,,,par)"



Mon, 06 Sep 2004 16:45:56 GMT  
 Omitting param-s
Try void 0 as in

myMethod(void 0, "something", void 0);

R.


Quote:
> Is there a way to omit optional parameters in JScript as in VBScript?
> Like "func(,,,par)"



Tue, 07 Sep 2004 00:10:29 GMT  
 Omitting param-s

| Is there a way to omit optional parameters in JScript as in VBScript?
| Like "func(,,,par)"

Try using the undefined keyword... It's a big word, but will work.

Though when I risk getting into a situation like this, I usually make my
functions regard as "not supplied" parameters when they are either undefined
or null:

if ((typeof V == 'undefined') || (V == null)) V = DEFAULT;

So that I can write a smaller line of code:

func(null,null,null,par);

But the best idea is to dispose parameters in a way this never happens. If
it's completely impossible, you should consider creating associative arrays
as parameters.

--
:: "Ekevu Guepardo" ::
:: Acinonyx jubatus ::
:: Porto Alegre, BR ::



Tue, 07 Sep 2004 01:20:59 GMT  
 Omitting param-s
function parmFnc (s){
  var a = s.split(',')
  for (i=0;i<a.length;i++) alert(a[i])

Quote:
}

parmFnc (',,,1,"text",,3')

Jacek

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Tue, 07 Sep 2004 03:19:32 GMT  
 Omitting param-s
   parmFnc (',,,1,"New York, NY",,3')

Gets ugly when the "text" param contains a comma:

== '"New York'
== ' NY"'

L8R,
Jim Rofkar.


| function parmFnc (s){
|   var a = s.split(',')
|   for (i=0;i<a.length;i++) alert(a[i])
| }
| parmFnc (',,,1,"text",,3')
|
| Jacek



Tue, 07 Sep 2004 11:31:33 GMT  
 Omitting param-s
Inside your function, you can also reference the "arguments" property to
determine the type and value of each argument passed into the function.
Like so:

  function test() {
    for (var i = 0; i < test.arguments.length; i++)
      {
      var arg = test.arguments[i];
      alert("arg#" + i + ", type=" + typeof(arg) + ", val=" + arg);
      }
  }

  test(1);
  test(undefined, undefined, 1);

Hope this helps,
Jim Rofkar.


| Is there a way to omit optional parameters in JScript as in VBScript?
| Like "func(,,,par)"



Tue, 07 Sep 2004 11:39:05 GMT  
 Omitting param-s
Thank you, all!
I will try 'void 0' and 'undefined'.

I use ADO components and recently encountered
that using 'null' for some optional param-s can bring
some unexpected results. For example:

// 'cmd'  is ADO's Command object

cmd.CommandText = "INSERT INTO Tbl (Fld) VALUES (?)";
cmd.Parameters.Append(cmd.CreateParameter("fld", adInteger));
cmd.Parameters("fld").Value = some_int;
cmd.Execute(null, null, adExecuteNoRecords);

Becouse all sources I've read recommend to use 'adExecuteNoRecords'
option, I do so. But the second param of Command::Execute() is an optional
array of values for parameterized query. So I used 'null' because parameter
types
and values are defined in prior lines. And this passed 'null'  as value for
query's parameter (?).



Tue, 07 Sep 2004 12:43:57 GMT  
 Omitting param-s
vbscript *assumes* an omitted parameter is 'null'. JScript requires you
to pass an explicit null. hence in the case of ADO connection's open()
method :

VBScript :
objConn.execute(actionquery, , adExecuteNoRecords)

JScript :
objConn.execute(actionquery, null, adExecuteNoRecords)

see the difference?

if you're writing the function rather than just using it, you can do
this

function blah()   {
   var arg1 = arguments[0];
   var arg2 = arguments[1];

Quote:
}

thereby avoiding trouble with omitted arguments, though how you keep
track of which is which is your problem. JScript doesn't allow function
overloading as Java does, so generally you'll find writing functions
with optional parameters to be, erm, different.

Atrax - MVP [Microsoft Most Valued Professional]

http://www.infinitemonkeys.ws/

Host with me for $100 a year!
http://www.atrax.ws/hosting/

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Tue, 07 Sep 2004 13:23:26 GMT  
 Omitting param-s
I do not thing so.

Jacek

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Wed, 08 Sep 2004 22:07:20 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. ScriptControl Eval(function VB, param, param) How pass parameter

2. PARAM TAG: Control does not Show after reading PARAM values

3. clone of checkbox omits attribute ..

4. in landscape ghostview omits parts of the page

5. Testing for omitted query string variables, how?

6. how to omit optional parameter in jscript function?

7. how to use url.Encode for NS problem w/ params in URL

8. PARAM problem

9. Passing multiple params to VBScript from HTML

10. Getting param values for an unidentified object

11. Geting Outbound params back in ASP??

12. JScript does not seem to understand the OUT params

 

 
Powered by phpBB® Forum Software