473,387 Members | 1,844 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,387 software developers and data experts.

Re: multiple parameters in function

jodleren wrote:
On Jul 2, 12:04 pm, jodleren <sonn...@hot.eewrote:
>I want to pass one or two parameters to a function, such as

function OpenDirSel(input, 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(input, 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(input);
}

or

function openDirSel(input)
{
/*
* 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(input);
}

and then

if (!openDirSel("BOO!"))
{
// DEBUG: `undefined' converts to `false'
window.alert("openDirSel: Invalid second argument!");
}
Like in
<input name="btn_dir1" type="button" value=" ... "
onclick="OpenDirSel(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.org/>
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
Jul 2 '08 #1
1 1305
Thomas 'PointedEars' Lahn wrote:
jodleren wrote:
>On Jul 2, 12:04 pm, jodleren <sonn...@hot.eewrote:
>>I want to pass one or two parameters to a function, such as

function OpenDirSel(input, 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(input, 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(input);
}

[...]
and then

if (!openDirSel("BOO!"))
{
// DEBUG: `undefined' converts to `false'
window.alert("openDirSel: Invalid second argument!");
}
Hmmm, to explain better, I should have returned `true' if all necessary
arguments were passed:

function openDirSel(input, 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(input);
return true;
}
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Jul 2 '08 #2

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

Similar topics

4
by: Angelos | last post by:
Ok... I have to make this administation area where I have multiple Contents to add edit delete publish . The problem is that I don't know what is the best way of making the forms. At the moment I...
66
by: Darren Dale | last post by:
Hello, def test(data): i = ? This is the line I have trouble with if i==1: return data else: return data a,b,c,d = test()
9
by: Richard Hunt | last post by:
What is the best way to get two values back from a function? I am working through 'The C Programming Language', but I felt like taking a bit of time off to write another program. The program...
9
by: lbj137 | last post by:
I have two files: A.c and B.c. In both files I define a global variable, int xxxx; When I compile with a green hills compiler (and also i think with a GNU compiler) I get no errors or warnings....
2
by: Asha | last post by:
greetings, i'm doing a multiple insert into the db through a store proc. i'm very sure the sp has nothing wrong. below are my implementation code and error msg. thanks in advance for the help ...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
16
by: Nikolay Petrov | last post by:
How can I return multiple values from a custom function? TIA
0
by: Andrew Brook | last post by:
I have written a WSDL file and im experiencing a problem with specifying parameters for an operation. I was expecting for wsdl.exe to produce an abstract function with three parameters (because of...
4
by: Nathan Sokalski | last post by:
I am a beginner with AJAX, and have managed to learn how to use it when passing single parameters, but I want to return more than one value to the client-side JavaScript function that displays it....
7
by: andrewfsears | last post by:
I have a question: I was wondering if it is possible to simulate the multiple constructors, like in Java (yes, I know that the languages are completely different)? Let's say that I have a class...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.