16
7

More than 5 years have passed since last update.

関数の引数の数を取得

Posted at

length プロパティで取得できます。すごく基本的なことなのに知りませんでした。

(function () {}).length
// -> 0

(function (a, b, c) {}).length
// -> 3

関数の中では arguments.callee.length で取得できます。実際に渡された引数の数とは別モノです。

(function (a, b, c) {
  return [arguments.callee.length, arguments.length];
})('Hello, World!');
// -> [3, 1]
16
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
7