Function.length

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 (en-US). Por contraste, arguments.length (en-US) é local para a função e fornece o número de argumentos que foram realmente passados.

Propriedade de Dados do construtor Function

O construtor Function é propriamente um objeto Function. A proproedade de dados do seu length tem o valor de 1. Os atributos da propriedade são: Escrita: false, Enumerável: false, Configurável: true.

Propriedades do objeto prototype de Function

A propriedade length do objeto prototype Function tem o valor de 0.

Exemplos

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 */

Especificações

Specification Status Comment
ECMAScript 1st Edition (ECMA-262) Padrão Initial definition. Implemented in JavaScript 1.1.
ECMAScript 5.1 (ECMA-262)
The definition of 'Function.length' in that specification.
Padrão
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'Function.length' in that specification.
Padrão The configurable attribute of this property is now true.

Compatibilidade com navegadores

BCD tables only load in the browser

Veja tambem