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:
- Using different names in the first place
- Using optional arguments like
y = y || 'default'
- Using number of arguments
- Checking types of arguments
- Or how?
No comments:
Post a Comment