What you want is this. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/length
If the parameter names are guaranteed not to be consistent throughout the code and will never be softened in any way, you do not want to check whether this parameter is assigned, "done". In most cases, developers should have the right to name their functional parameters.
In addition, javascript code (for the browser) is usually faded and distorted, and parameter names are shortened. If the names are changed, this will violate your function.
However, what you most likely want to do is decide how many parameters are set by the function, and what can be done with Function.length
.
However, this is also not a reliable solution, because you can always specify nothing and still get parameter values โโwith arguments
.
In JavaScript, it is usually bad to assume that something will work as I intended. Because you never know who will do what with their codes.
The language itself is so dynamic in different ways, you have to be very careful before creating your functions / APIs.
from MDN:
console.log( (function () {}).length ); console.log( (function (a) {}).length ); console.log( (function (a, b) {}).length ); console.log( (function (...args) {}).length );
source share