Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Function.length

length 属性指明函数的形参个数。

Function.length 属性的属性特性:
writable false
enumerable false
configurable true

描述

length 是函数对象的一个属性值,指明该函数期望多少个参数,意即形参的个数。数量不包括剩余参数。相比之下,  arguments.length 是函数被调用时实际传参的个数。

Function 构造器的属性

Function 构造器本身也是个Function。他的 length 属性值为 1 。该属性 Writable: false, Enumerable: false, Configurable: true.

Function 原型对象的属性

 Function  原型对象的 length 属性值为 0 。

例子

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

规范

Specification Status Comment
ECMAScript 1st Edition (ECMA-262) Standard Initial definition. Implemented in JavaScript 1.1.
ECMAScript 5.1 (ECMA-262)
Function.length
Standard  
ECMAScript 2015 (6th Edition, ECMA-262)
Function.length
Standard The configurable attribute of this property is now true.
ECMAScript 2017 Draft (ECMA-262)
Function.length
Draft  

相关链接

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) ? ? ?

参考

 

文档标签和贡献者

 此页面的贡献者: yenshen, teoli, ziyunfei, tiansh
 最后编辑者: yenshen,