javascript原型和继承 [英] javascript prototypes and inheritance
问题描述
我的问题是对象是原型链上的最后一个对象,所有对象都从对象继承属性和方法,它是如何从Function.prototype继承方法的,为什么Object.__proto__ === Function.prototype
//是,为什么Object.__proto__
不为空.
My question is Object is last on prototype chain all objects inherit properties and methods from it how it is inherit methods from Function.prototype, why Object.__proto__ === Function.prototype
// true, why Object.__proto__
is not null.
推荐答案
函数也是一个对象.因此它也继承自Object.
Function is also an object. So it inherits from Object too.
但是请不要被Object.__proto__
所迷惑.那是浏览器添加的东西,实际上并不是语言的一部分.因此,请勿依赖或使用它.
But don't be confused by Object.__proto__
. That's something the browser adds and isn't actually part of the language. So don't rely on it or use it.
本质上,Function.prototype
是Object.__proto__
.
这篇关于javascript原型和继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!