Before I start writing this post, I already tried the codes below;
function foo(a){
alert(a);}
function foo(a, b){
alert(a + ' ' + b);}
And in a function which called when the page is loaded, I called the two functions as this: foo(1); foo(1, 2);
Then I firstly got "1 undefined" and then "1 2".
What I expected first is that I might be able to declare the same name of functions with different parameters like Java; but I'm not sure I can. At least I'm sure that declaring function foo(a, b){...}
and function foo(b, c){...}
is prohibited.
No comments:
Post a Comment