javascript - 'Function' 上的 MDN 描述感到困惑,Function.length 是 Function 或 Function.prototype 的属性

标签 javascript

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

据说

Properties and Methods of Function 

The global Function object has no methods or properties of its own, however, since it is a function itself it does inherit some methods and properties through the prototype chain from 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 (!!!here is what I confused, why it does not display 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 的属性?

欢迎您发表评论

最佳答案

来自MDN docs on Function.length :

The Function constructor is itself a Function object. Its length data property has a value of 1.

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

The length property of the Function prototype object has a value of 0.

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

关于javascript - 'Function' 上的 MDN 描述感到困惑,Function.length 是 Function 或 Function.prototype 的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39524513/

相关文章:

javascript - 是否可以使用 ReactNative 组件作为其节点之一来创建 ES6 map ?

javascript - HTML 类型 ="search"检测清除按钮支持

javascript - 如何使用 ES6 解构添加默认值和别名?

javascript - 如何在 AngularJS 中打印 JSON 对象的元素?

javascript - 无法分配给对象 'closed' 的只读属性 '[object Object]'

javascript - 根据列表项点击更改 DIV 内容

javascript - 渲染一个复选框并根据从一个数据集到另一个数据集的值的存在来检查它

javascript - 如何在 handleSubmit 中从 react-query 实现 useMutation

javascript - JavaScript 重定向后无法返回

javascript - 在 ReactJS 中继续之前等到函数返回一个值