Friday, February 22, 2019

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

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...