Vanilla 1.1.4 is a product of Lussumo. More Information: Documentation, Community Support.
Does JavaScript support Method Overloading? Please provide an explanation with your answer. This question is open for the next 2 weeks. I will post the correct answer on May 15, 2008.
Let the games begin! :)
I'm not that good in Javascript. I am just sinking my teeth into it.
But I know that it does not support method overloading. You have to work around that using some lousy technique. :)
The official answer is NO. Technically however, it is possible. Allow me to explain if I may:
Copy this code snippet, paste and save it, in your favorite text editor and run it. Of course, ignore any wrong/missing tags, etc:
================
Untitled
function overload() {
var howMany = arguments.length;
var sum;
if(howMany == 1) {
sum = arguments[0] + 5;
} else {
sum = arguments[0] + arguments[1];
}
alert(sum);
}
2 arguments - overload(10, 10)
================
The trick is that every function has an "arguments" property. By accessing the number of arguments you can technically perform method overloading and get away with it ;)
1 to 3 of 3