// add.js
function add() {
switch (arguments.length) {
case 2:
return arguments[0] + arguments[1];
case 3:
return arguments[0] + arguments[1] + arguments[2];
case 4:
return arguments[0] + arguments[1] + arguments[2] + arguments[3];
default:
throw new Error("Too few or too many arguments. Number of arguments: " + arguments.length);
}
}
module.exports = { add };
Declaration file style:
---
--- --- ---(Gist: https://gist.github.com/Robert-Fairley/98a2da3f0361e524f4e05...)
It will default to the first function name, but it definitely allows for overloading the number of parameters.
It's not perfect as you do still have to implement the function as it would need to be implemented for JS