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 neede
For your use case, this is how I would tackle it with ES6
(since it's already the end of 2017):
const foo = (x, y, z) => {
if (y && z) {
// Do your foo(x, y, z); functionality
return output;
}
// Do your foo(x); functionality
return output;
}
You can obviously adapt this to work with any amount of parameters and just change your conditional statements accordingly.