Ray, from one novice to another :)
I think you can use optional arguments with Jscript. but you can't
skip a parameter... eg if you leave off arg3 below you also have to
leave off 4 & 5.
if there is a way of just skipping arg3 below then I dont know it and
maybe a guru will help :)
Also I've learned you can pass an object to a function (myfunc2 below)
which might help
HTH
Al.
function Myfunc (arg1, arg2, arg3, arg4, arg5) {
// the below will asign the value after the || if the arg1
// is "undefined/null"
var a1 = arg1 || ""; // undefined...set to ""
var a2 = arg2 || 0; // undefined...set to 0
var a3 = arg3 || 0; // undefined...set to 0
var a4 = arg4 || ""; // undefined...set to ""
var a5 = arg5 || 0; // undefined...set to 0
// or you can do this:
if (typeof arg1 == "undefined") {
arg1 = "";
}
//etc
}
// calling a func to pass an object.
// note the curly brackets INSIDE the rounded ones.
var RetVal = myFunc2 ( {x :10, y:20, z : 30, text:"myText: "} );
// function "requires" x & y properties... z & text is optional
function myFunc2 (obj) {
var calc = obj.x * obj.y;
if (typeof obj.z == "number") {
calc *= obj.z;
}
if (typeof obj.text == "string") {
return obj.text + calc
}
return calc;
}
On Wed, 14 Jan 2004 15:35:38 -0500, "Ray at <%=sLocation%>"
<myfirstname at lane34 dot com> wrote:
What language? VBScript or JScript? Optional arguments are not supported
in VB Script, unfortunately. Here's a work around that someone has come up
with. http://www.4guysfromrolla.com/webtech/071801-1.shtml
I'm ~pretty~ sure that jscript does not support optional arguments either,
but hopefully someone can verify that, as I'm a jscript novice at best.
Ray at work
"JT" <je******@sppinc.net> wrote in message
news:OL**************@TK2MSFTNGP11.phx.gbl... how can i declare a function that will accept an optional parameter?
something like:
function newFunc(strValue1, strValue2) --where strValue2 is optional.
thanks much.