MDN描述与函数'混淆,Function.length是Function或Function.prototype的属性

时间:2016-09-16 05:50:20

标签: javascript

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function

它说

Properties and Methods of Function 
  

全局Function对象没有自己的方法或属性,因为它本身就是一个函数,它通过Function.prototype的原型链继承了一些方法和属性。

然后继续说那个

Function prototype object 
Properties

Function.arguments 
An array corresponding to the arguments passed to a function. This is deprecated as property of Function, use the arguments object available within the function instead.
Function.arity 
Used to specifiy the number of arguments expected by the function, but has been removed. Use the length property instead.
Function.caller 
Specifies the function that invoked the currently executing function.
  

Function.length(!!!这里我很困惑,为什么它不显示 Function.prototype.length

Specifies the number of arguments expected by the function.
Function.name
The name of the function.
Function.displayName 
The display name of the function.
  

Function.prototype.constructor

Specifies the function that creates an object's prototype. See Object.prototype.constructor for more details.
Methods

只是想知道Function.length是否是Function.prototype的属性?

您的评论欢迎

1 个答案:

答案 0 :(得分:0)

来自MDN docs on Function.length

  

Function构造函数本身就是一个Function对象。其length数据属性的值为1.

Function.length等于1,因为Function构造函数采用一个正式参数 - 函数体。

  

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

Function.prototype.length等于0,因为Function.prototype不接受任何参数。