• Post Reply Bookmark Topic Watch Topic
  • New Topic

overwriting  RSS feed

 
Kinga Cserveny
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if I have a FormSubmit(this) java script function, could I have another one called FormSubmit but taking 3 parameters. Can jave script function be overwritten?
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, I am not aware that JavaScript functions can be overloaded.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But what you can do is to test for the existance of the arguments. This way, you could call a three-parameter function with fewer arguments and test whether the parameters were passed or not.
For example, let's say we define function xyz as:

You can call this function using any number of parameters. E.g.:

Any call you make with "missing" arguments will cause the corresponding parameters to evaluate as null.
Not as clean as overloading, but at least you can get the desired effect.
hth,
bear
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!