diff options
| author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
|---|---|---|
| committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
| commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
| tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/ja/web/javascript/reference/global_objects/function/length | |
| parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
| download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip | |
initial commit
Diffstat (limited to 'files/ja/web/javascript/reference/global_objects/function/length')
| -rw-r--r-- | files/ja/web/javascript/reference/global_objects/function/length/index.html | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/files/ja/web/javascript/reference/global_objects/function/length/index.html b/files/ja/web/javascript/reference/global_objects/function/length/index.html new file mode 100644 index 0000000000..f64e2ee9d7 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/function/length/index.html @@ -0,0 +1,76 @@ +--- +title: Function.length +slug: Web/JavaScript/Reference/Global_Objects/Function/length +tags: + - Function + - JavaScript + - Property +translation_of: Web/JavaScript/Reference/Global_Objects/Function/length +--- +<div>{{JSRef}}</div> + +<p><strong><code>length</code></strong> プロパティは、関数が期待する引数の数を示します。</p> + +<div>{{EmbedInteractiveExample("pages/js/function-length.html")}}</div> + +<div class="hidden">このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力したい場合は、 <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> をクローンしてプルリクエストを送信してください。</div> + +<div>{{js_property_attributes(0,0,1)}}</div> + +<h2 id="Description" name="Description">解説</h2> + +<p><code>length</code> は function オブジェクトのプロパティであり、関数が期待する引数の数、つまり形式上の引数の数を示します。この数に{{jsxref("rest_parameters", "残余引数", "", 1)}}は含まれず、既定値を持つ引数が最初に登場する前までしか含みません。これに対し、 {{jsxref("Functions_and_function_scope/arguments/length", "arguments.length")}} は関数のローカルスコープ内で用いられ、関数が実際に受け取った引数の数、つまり実引数の数を参照するのに用いるものです。</p> + +<h3 id="Data_property_of_the_Function_constructor" name="Data_property_of_the_Function_constructor">Function コンストラクターのデータプロパティ</h3> + +<p>{{jsxref("Function")}} コンストラクター自体は、{{jsxref("Function")}} オブジェクトです。この <code>length</code> データプロパティの値は 1 です。プロパティの属性は、 Writable: <code>false</code>、Enumerable: <code>false</code>、Configurable: <code>true</code> です。</p> + +<h3 id="Property_of_the_Function_prototype_object" name="Property_of_the_Function_prototype_object">Function プロトタイプのオブジェクトのプロパティ</h3> + +<p>{{jsxref("Function")}} プロトタイプオブジェクトの length プロパティの値は 0 です。</p> + +<h2 id="Examples" name="Examples">例</h2> + +<h3 id="Using_function_length" name="Using_function_length">関数の length の使用</h3> + +<pre class="brush: js notranslate">console.log(Function.length); /* 1 */ + +console.log((function() {}).length); /* 0 */ +console.log((function(a) {}).length); /* 1 */ +console.log((function(a, b) {}).length); /* 2 etc. */ + +console.log((function(...args) {}).length); +// 0, rest parameter は数に含まれない + +console.log((function(a, b = 1, c) {}).length); +// 1, 既定値を持つ引数が最初に登場する前までの +// 引数だけが数に含まれる</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('ESDraft', '#sec-function-instances-length', 'Function.length')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div> +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<p>{{Compat("javascript.builtins.Function.length")}}</p> +</div> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>{{jsxref("Function")}}</li> +</ul> |
