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;
}