aboutsummaryrefslogtreecommitdiff
path: root/files/de/web/javascript/reference/global_objects/function/length/index.html
blob: 3eca57b92a3edc26c025b1b25ca46af64fa59399 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
---
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>Die <code><strong>length</strong></code> Eigenschaft gibt die Anzahl der von der Funktion erwarteten Parameter an.</p>

<div>{{EmbedInteractiveExample("pages/js/function-length.html")}}</div>



<div>{{js_property_attributes(0,0,1)}}</div>

<h2 id="Description" name="Description">Beschreibung</h2>

<p><code>length</code> ist eine Eigenschaft eines Funktionsobjekts und zeigt an, wie viele Argumente die Funktion erwartet, d.h. die Anzahl der formalen Parameter. Diese Anzahl beinhaltet jedoch nicht den {{jsxref("rest_parameters", "rest Parameter", "", 1)}} und bezieht außerdem auch nur die Parameter ein, die in der Reihenfolge vor dem ersten Parameter mit einem Default-Wert sind. Im Gegensatz dazu ist {{jsxref("Functions/arguments/length", "arguments.length")}} eine in jeder Funktion verfügbare lokale Variable, die die tatsächliche Anzahl der übergebenen Argumente angibt.</p>

<h3 id="Dateneigenschaft_des_Function_Konstruktors">Dateneigenschaft des <code>Function</code> Konstruktors</h3>

<p>Der {{jsxref("Global_Objects/Function", "Function")}} Konstruktor ist selbst ein {{jsxref("Global_Objects/Function", "Function")}} Objekt. Seine Eigenschaft <code>length</code> hat den Wert 1. Dessen Attribute lauten: Writable: <code>false</code>, Enumerable: <code>false</code>, Configurable: <code>true</code>.</p>

<h3 id="Eigenschaft_des_Function_prototype_Objekt">Eigenschaft des <code>Function</code> prototype Objekt</h3>

<p>Die length-Eigenschaft des {{jsxref("Global_Objects/Function", "Function")}} prototype Objekts hat den Wert 0.</p>

<h2 id="Examples" name="Examples">Beispiele</h2>

<pre class="brush: js">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 wird nicht gezählt

console.log((function(a, b = 1, c) {}).length);
// 1, nur Parameter vor dem ersten Parameter mit
// einem Default-Wert werden gezählt
</pre>

<h2 id="Spezifikationen">Spezifikationen</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Spezifikation</th>
   <th scope="col">Status</th>
   <th scope="col">Kommentar</th>
  </tr>
  <tr>
   <td>{{SpecName('ES1')}}</td>
   <td>{{Spec2('ES1')}}</td>
   <td>Initiale Definition. Implementiert in JavaScript 1.1.</td>
  </tr>
  <tr>
   <td>{{SpecName('ES5.1', '#sec-15.3.5.1', 'Function.length')}}</td>
   <td>{{Spec2('ES5.1')}}</td>
   <td> </td>
  </tr>
  <tr>
   <td>{{SpecName('ES6', '#sec-function-instances-length', 'Function.length')}}</td>
   <td>{{Spec2('ES6')}}</td>
   <td>Das <code>configurable</code> Attribut dieser Eigenschaft ist nun <code>true</code>.</td>
  </tr>
  <tr>
   <td>{{SpecName('ESDraft', '#sec-function-instances-length', 'Function.length')}}</td>
   <td>{{Spec2('ESDraft')}}</td>
   <td> </td>
  </tr>
 </tbody>
</table>

<h2 id="Browserkompatibilität">Browserkompatibilität</h2>

<div>


<p>{{Compat("javascript.builtins.Function.length")}}</p>
</div>

<h2 id="Siehe_auch">Siehe auch</h2>

<ul>
 <li>{{jsxref("Global_Objects/Function", "Function")}}</li>
</ul>