aboutsummaryrefslogtreecommitdiff
path: root/files/es/web/javascript/reference/global_objects/function/length/index.html
blob: 21737188a54d2a43421ba0f1f1d591a561687b46 (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
---
title: Function.length
slug: Web/JavaScript/Reference/Global_Objects/Function/length
tags:
  - JavaScript
  - Propiedad
  - función
translation_of: Web/JavaScript/Reference/Global_Objects/Function/length
original_slug: Web/JavaScript/Referencia/Objetos_globales/Function/length
---
<div>{{JSRef("Global_Objects", "Function")}}</div>

<h2 id="Summary" name="Summary">Sumario</h2>

<p>La propiedad <code><strong>length</strong></code> especifica el número de argumentos esperados por la función.</p>

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

<h2 id="Description" name="Description">Descripción</h2>

<p><code>length</code> es la propiedad de una función objeto, e indica el número de argumentos que una función requiere, por ejemplo, el número de parámetros formales. Este número no incluye {{jsxref("rest_parameters", "rest parameter", "", 1)}}. En cambio, {{jsxref("Functions_and_function_scope/arguments/length", "arguments.length")}} es local a una función y aporta el número de argumentos actuales pasados a una función.</p>

<h3 id="Propiedades_de_la_Función_constructora">Propiedades de la <code>Función</code> constructora</h3>

<p>El {{jsxref("Global_Objects/Function", "Function")}} constructor en sí mismo es {{jsxref("Global_Objects/Function", "Function")}} un objeto. Sú <code>propiedad length</code> tiene el valor 1. Los atributos son: Grabable: <code>false</code>, Enumerable: <code>false</code>, Configurable: <code>true</code>.</p>

<h3 id="Propiedad_de_la_Función_prototype_object">Propiedad de la  <code>Función</code> prototype object</h3>

<p>La propiedad length del {{jsxref("Global_Objects/Function", "Function")}} objeto prototype tiene el valor 0.</p>

<h2 id="Examples" name="Examples">Ejemplos</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, resto de parámetros no se contemplan */
console.log((function(a, b = 1, c) {}).length); /* 1, solo parámetros antes del primero con un valor por defecto son contados */
</pre>

<h2 id="Especificaciones">Especificaciones</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Especificación</th>
   <th scope="col">Estado</th>
   <th scope="col">Comentario</th>
  </tr>
  <tr>
   <td>ECMAScript 1st Edition.</td>
   <td>Standard</td>
   <td>Definición inicial. Implementado en JavaScript 1.1.</td>
  </tr>
  <tr>
   <td><code>length</code> property of the {{jsxref("Global_Objects/Function", "Function")}} constructor:<br>
    {{SpecName('ES5.1', '#sec-15.3.3.2', 'Function.length')}}<br>
    <code>length</code> property of the {{jsxref("Global_Objects/Function", "Function")}} prototype object:<br>
    {{SpecName('ES5.1', '#sec-properties-of-the-function-prototype-object', 'Function.length')}}<br>
    <code>length</code> property of {{jsxref("Global_Objects/Function", "Function")}} instances:<br>
    {{SpecName('ES5.1', '#sec-15.3.5.1', 'Function.length')}}</td>
   <td>{{Spec2('ES5.1')}}</td>
   <td></td>
  </tr>
  <tr>
   <td><code>length</code> property of the {{jsxref("Global_Objects/Function", "Function")}} constructor:<br>
    {{SpecName('ES6', '#sec-function.length', 'Function.length')}}<br>
    <code>length</code> property of the {{jsxref("Global_Objects/Function", "Function")}} prototype object:<br>
    {{SpecName('ES6', '#sec-15.3.4', 'Function.length')}}<br>
    <code>length</code> property of {{jsxref("Global_Objects/Function", "Function")}} instances:<br>
    {{SpecName('ES6', '#sec-function-instances-length', 'Function.length')}}</td>
   <td>{{Spec2('ES6')}}</td>
   <td>El atributo <code>configurable</code> de esta propiedad ahora es <code>true</code>.</td>
  </tr>
 </tbody>
</table>

<h2 id="Compatibilidad_con_navegadores">Compatibilidad con navegadores</h2>

{{Compat("javascript.builtins.Function.length")}}

<h2 id="Ver_también">Ver también</h2>

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