Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于 JS 的原型 #4

Open
liangbus opened this issue Nov 9, 2019 · 3 comments
Open

关于 JS 的原型 #4

liangbus opened this issue Nov 9, 2019 · 3 comments

Comments

@liangbus
Copy link
Owner

liangbus commented Nov 9, 2019

先祭出一张网红图占个坑
image

@liangbus liangbus changed the title 关于 JS 的继承 关于 JS 的原型 Dec 22, 2019
@liangbus
Copy link
Owner Author

@YuetTong
Copy link

YuetTong commented Mar 7, 2022

构造函数,通过prototype来存储要共享的属性和方法,也可以设置prototype指向现存的对象来继承该对象。

对象的__proto__指向自己构造函数的prototype。obj.proto.proto...的原型链由此产生,包括我们的操作符instanceof正是通过探测obj.proto.proto... === Constructor.prototype来验证obj是否是Constructor的实例。

Function本身就是函数,Function.__proto__是标准的内置对象Function.prototype。
Function.prototype.__proto__是标准的内置对象Object.prototype。

@YuetTong
Copy link

YuetTong commented Mar 7, 2022

函数的 prototype 属性指向了一个对象,这个对象正是调用该构造函数而创建的实例的原型
这是每一个JavaScript对象(除了 null )都具有的一个属性,叫__proto__,这个属性会指向该对象的原型

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants