473,385 Members | 1,355 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

Jul 20 '05 #1
7 14160
rf

"(-: Dan :-)" <nn*****@tiscalinet.it> wrote in message
news:3F***************@tiscalinet.it...
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?


No.

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

Cheers
Richard.
Jul 20 '05 #2
"(-: Dan :-)" <nn*****@tiscalinet.it> writes:
4. F1(1, ,3) Can I call 4th way?


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 - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #3
Lee
Lasse Reichstein Nielsen said:

"(-: Dan :-)" <nn*****@tiscalinet.it> writes:
4. F1(1, ,3)

Can I call 4th way?


Try
F1(1,undefined,3)


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

F1(1,-1,3);

Jul 20 '05 #4
JRS: In article <bm*********@drn.newsguy.com>, seen in
news:comp.lang.javascript, Lee <RE**************@cox.net> posted at Fri,
10 Oct 2003 08:23:59 :-
Lasse Reichstein Nielsen said:
"(-: Dan :-)" <nn*****@tiscalinet.it> writes:
4. F1(1, ,3)

Can I call 4th way?


Try
F1(1,undefined,3)


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

F1(1,-1,3);


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.demon.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
Jul 20 '05 #5
>

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.


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

Jul 20 '05 #6
Lee <RE**************@cox.net> writes:
It would seem to be cleaner to supply the default value
as found in the documentation for that function:

F1(1,-1,3);


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.length, or by checking
'1' in arguments
(although it seems to be bugged in Opera)

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #7
Dr John Stockton <sp**@merlyn.demon.co.uk> writes:
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.


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.undefined = window.undefined;
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 - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: William Ryan | last post by:
I just picked up a copy of John Robbins' debugging book and started to look at disassembled code. Anyway, I hate optional Parameters in VB, but I was checking them out to see what IL is created. ...
16
by: ad | last post by:
Does C#2.0 support optional parameters like VB.NET: Function MyFunction(Optional ByVal isCenter As Boolean = False)
4
by: Jeff | last post by:
Help!! I'm trying to convert a visual basic stand alone program into a Web Program using C#. There are a lot of Oracle packages already written that I am trying to use (unsuccessfully). Can...
1
by: Do | last post by:
Hi: What's the syntax for an optional parameter in my function? I've done so many ASP 3.0 Web Classes that I haven't experienced the "Optional" parameter. Eg. Public function adduser(ByVal...
10
by: John Morgan | last post by:
Does anyone know what parameter should be used instead of Date = 0 for the optional parameter in the following function? Public Function dhAge(ByVal dtmBD As Date, Optional ByVal dtmDate As Date...
10
by: deko | last post by:
In VB, I could do this: MyFuncrion(this As String, that As Integer, Optional otherThing As Boolean) do stuff here End Function In C#, I can use "out" to return multiple values from a method,...
1
by: Memphis Steve | last post by:
Is it possible to combine multiple javascipts into one file and then call that file from a linked URL in the head section of an XHTML file? Here are the two scripts I want to use with the...
18
by: dhtml | last post by:
Array.splice({}) What should it do? I think it should return a new Array with length 0. Array.splice(arr, start, deleteCount ]]) http://bclary.com/2004/11/07/#a-15.4.4.12 Example:
0
amitpatel66
by: amitpatel66 | last post by:
There is always a requirement that in Oracle Applications, the Concurrent Program need to be execute programatically based on certain conditions/validations: Concurrent programs can be executed...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.