Skip to content

Count all arguments of a function (including arguments with default values)

License

Notifications You must be signed in to change notification settings

KooiInc/count-es-function-arguments

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 

Repository files navigation

ESCountArguments

Count all arguments of a function (including arguments with default values)

The native length method of an ES function returns the number of the function arguments, e.g. function(a, b) {}).length is 2. But if the function knows arguments with default values, those are not included. So

function x(a, b=2, c=3) {};
console.log(x.length); // => 1;

This small utility library also counts the arguments with default values.

This will always be an approximation, good for almost all cases but it may not be accurate for edge cases (like very complex strings/strings within values that are Objects, function declarations as parameters etc.).

Use import countArguments from '//kooiinc.github.io/ESCountArguments/CountArgumentsLib.js' to use this utility.

See this Stackblitz project for tests and syntax

About

Count all arguments of a function (including arguments with default values)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published