This is expected behavior.
JavaScript does not have function overloading, so when you define two functions with the same name in the same scope, only the last one is accessible.
The way to get a similar functionality is to test the number of actual arguments:
--- script ---
function a(p1, p2) {
if (arguments.length > 1) {
globalVariable = "2 param called";
} else {
globalVariable = "1 param called";
}
}
---------------
Fair warning: accessing the "arguments" object has a slight performance overhead, so if you use it in a tight loop, you might want to just test whether p2 is undefined instead:
if (typeof p2 == "undefined") { ...
This obviously doesn't work if the undefined value is a valid argument to the two-argument variant of the function.
Best of luck
Lasse
--
Lasse R.H. Nielsen
l...@google.com'Faith without judgement merely degrades the spirit divine'