Hi Ziv,
Is there an opiton of overloading methods? |
Not really. That is, you can't define several functions with the same name but different parameter sets - neither in VBScript, nor in JScript, nor in DelphiScript.
However, since these languages have no strong typing, you can pass different data types - strings, numbers, and so on - in the same parameter. You can then use
aqObject.GetVarType inside the function to check the parameter's data type and implement the needed conditional logic. Like this, for example:
function Main()
{
Log.Message(Add10(5));
Log.Message(Add10("7"));
}
function Add10(Value)
{
switch (aqObject.GetVarType(Value))
{
case varInteger: return Value + 10;
case varOleStr: return parseInt(Value) + 10;
default: throw "Invalid parameter type";
}
}
Search
VBScript overloading and
JScript overloading for more examples.
Another quastion, is there an opiton to set default values for paremeters in methods? |
In DelphiScript - yes, see
Default Values of Routine Parameters.
In VBScript, you can pass
Null in place of non-used arguments or use an arguments array as explained here:
Optional Arguments in VBScriptOptional Arguments in VBScript, Part 2In JScript, you can pass an arbitrary number of arguments to a function or pass them using an array, dictionary or custom object:
Function overloading in JavaScript - Best practicesHow to implement polymorphism in JavaScriptUsing optional parameters in JavaScript functionsOptional Function Arguments in JavaScript