- 1
Can JAVASCRIPT have function overloading??
5 Answers
+ 3
Function overloading make sense only in typed languages, but JS is duck typing one, so there's no difference between a function expecting a specific type of argument: overloading is needed to differenciate function to be run regarding it's context arguments, what you would do rather by testing the type of arguments inside function in JS...
In the other hand, you can have function overwritting, just by redefining even built-in functions:
document.write = function(s) {
console.log(s);
}
will bypass the standard document.write() execution and redirect output to console ^^
+ 2
@ayush:
Why marking my answer as best, then unmarking it and set it again to @Jordan?... all the more without upvoting any? @@
+ 1
Nope but there are other options
https://stackoverflow.com/questions/456177/function-overloading-in-javascript-best-practices
+ 1
thanks jordan
- 1
@visph
sorry i was unaware , i think it was pressed by mistake