Esta tradução está incompleta. Ajude atraduzir este artigo.
A propriedade length especifica o número de argumentos esperados pela função.
Property attributes of Function.length |
|
|---|---|
| Writable | no |
| Enumerable | no |
| Configurable | yes |
Descrição
length é uma propriedade de um objeto função, e indica quantos argumentos a função espera, i.e. o número de parametros formais. Este número não incluí o rest parameter. Por contraste, arguments.length é local para a função e fornece o número de argumentos que foram realmente passados.
Data property of the Function constructor
The Function constructor is itself a Function object. Its length data property has a value of 1. The property attributes are: Writable: false, Enumerable: false, Configurable: true.
Property of the Function prototype object
The length property of the Function prototype object has a value of 0.
Examples
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 is not counted */
Specifications
| Specification | Status | Comment |
|---|---|---|
| ECMAScript 1st Edition (ECMA-262) | Standard | Initial definition. Implemented in JavaScript 1.1. |
| ECMAScript 5.1 (ECMA-262) The definition of 'Function.length' in that specification. |
Standard | |
| ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'Function.length' in that specification. |
Standard | The configurable attribute of this property is now true. |
Browser compatibility
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Basic support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
| Configurable: true | ? | 37 (37) | ? | ? | ? |
| Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|
| Basic support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
| Configurable: true | ? | ? | 37.0 (37) | ? | ? | ? |
See also
Etiquetas do documento e colaboradores
Colaboradores desta página:
matheussilvasantos,
LucasRamos
Última atualização por:
matheussilvasantos,