Thursday, 14 April 2016

Function overloading in Javascript - Best practices

What is the best way(s) to fake function overloading in Javascript?



I know it is not possible to overload functions in Javascript as in other languages.
If I needed a function with two uses foo(x) and foo(x,y,z) which is the best / preferred way:




  1. Using different names in the first place

  2. Using optional arguments like y = y || 'default'

  3. Using number of arguments

  4. Checking types of arguments


  5. Or how?

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...