简体   繁体   English

在MDN网站中,为什么说Object.prototype继承自Function.prototype

[英]In MDN site, why does it say Object.prototype inherits from Function.prototype

I understand that Object.prototype. 我了解Object.prototype。 proto = null being end of the chain (so says the browsers console). proto = null是链的结尾(因此,浏览器控制台表示)。

In MDN site, at the Object.prototype page: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/prototype 在MDN站点的Object.prototype页面上: https : //developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/prototype

At the bottom of the page, under "Inheritance:" you will see "Function" with expandable properties & method underneath. 在页面底部的“继承:”下,您将看到“函数”及其下方的可扩展属性和方法。 To my understanding it says Object.prototype inherits methods such as Function.prototype.bind() etc 据我了解,它说Object.prototype继承了诸如Function.prototype.bind()等方法。

I can understand the Object constructor function shares the non-prototypal property/method (such as caller property) as it is constructed by the Function constructor fn. 我可以理解Object构造函数共享由Function构造函数fn构造的非原型属性/方法(例如调用者属性)。 But how does Object.prototype inherit from Function.prototype while Object.prototype. 但是Object.prototype是如何从Object.prototype继承自Function.prototype的。 proto is null? proto为空?

Can someone shed a light please? 有人可以照亮吗?

It's referring to what the Object constructor inherits from, not object instances. 它是指Object构造函数从中继承的内容,而不是对象实例。 All constructors are functions, so the Object function itself inherits from Function.prototype . 所有构造函数都是函数,因此Object函数本身继承自Function.prototype

When you see the notice down a bit on the page that says: 当您在页面上看到以下通知时:

Properties inherited from Function: arity, caller, constructor, length, name 从Function继承的属性:arity,调用方,构造函数,长度,名称

It's easier to understand what was meant by that -- it's referring to how properties such as Object.constructor and Object.length have been inherited from Function . 更容易理解其含义–指的是如何从Function继承诸如Object.constructorObject.length属性。

Anyway, it is true that Object.prototype.__proto__ === null -- Object.prototype does not inherit from Function.prototype at all, as you had thought. 无论如何,这事实Object.prototype.__proto__ === null - Object.prototype中没有从Function.prototype的继承所有的,因为你曾经想过。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM