dimanche 22 février 2015

Is a parameter count availabe in Javascript for an anonymous invoked function?



(function (a, b, c) {

console.log(arguments.length); // 2

} (1, 2) )


When the above function runs, the function can tell it was called with only two arguments via the arguments object's length property.


Is there also a way for the function to tell that it was expecting 3 arguments since a, b, & c are listed in the definition of the function?


In the above function:



console.log( what?) === 3?


I read through this answer Get a function's arity but it requires a reference (such as a name) to the function and does not answer my question with respect to the console.log being inside the function.





Aucun commentaire:

Enregistrer un commentaire