A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Function/length below:

Function: length - JavaScript | MDN

Function: length

Baseline Widely available

length は Function インスタンスのプロパティで、関数が期待する引数の数を示します。

試してみましょう
function func1() {}

function func2(a, b) {}

console.log(func1.length);
// 期待される出力結果: 0

console.log(func2.length);
// 期待される出力結果: 2
値

数値です。

書込可能 不可 列挙可能 不可 設定可能 可 解説

Function オブジェクトの length プロパティは、関数が期待する引数の数、つまり形式上の引数の数を示します。

これに対し、 arguments.length は関数のローカルスコープ内で用いられ、関数が実際に受け取った引数の数、つまり実引数の数を参照するのに用いるものです。

Function コンストラクター自体は、 Function オブジェクトです。この length データプロパティの値は 1 です。

歴史的な理由により、 Function.prototype は自身を呼び出すことができます。 Function.prototype の length は 0 の値を持ちます。

例 関数の length の使用
console.log(Function.length); // 1

console.log((() => {}).length); // 0
console.log(((a) => {}).length); // 1
console.log(((a, b) => {}).length); // 2 etc.

console.log(((...args) => {}).length);
// 0, rest parameter は数に含まれない

console.log(((a, b = 1, c) => {}).length);
// 1, 既定値を持つ引数が最初に登場する前までの
// 引数だけが数に含まれる

console.log((({ a, b }, [c, d]) => {}).length);
// 2, 分割パターンは、それぞれ単一の引数としてカウントされる
仕様書 ブラウザーの互換性 関連情報

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4