unexpected call to a function in Javascript -


I'm not really good at javascript, so I'm asking here.

Below is a sample code.

  & lt; Html & gt; & Lt; Top & gt; & Lt; Script & gt; Function Test (A) {Warning ('Surprise with a Parameter! First Function'); } Function test (one, two) {warning ('expected: second function with two parameters'); } & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body onload = "javascript: test ('first')" & gt; & Lt; / Body & gt; & Lt; / Html & gt;  

Question:

I expected it to be 'Wondering! The first function ' with one parameter will be alerted onload as I call the function with only one parameter.

  • Can anyone explain this to me?
  • And how can I make my way around it?

JavaScript does not support overloading; It just overwrites the function, so the last time the call will be called.

One way around it is to create just 1 function and to check some situations to see if variables are set or not.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -