__proto__
指向,当检索依赖对象自己不存在的属性时,就会一层一层地向上去查找建立对象的构造函数,一直找到Object
,就没有__proto__
的指向了。构造函数
首字母大写的函数。例如:javascript
function Person() { }
对象实例
对象有两种:css
new Function();
建立的对象;prototype
属性;__proto__
,这个属性指向该对象的原型(prototype
);constructor
属性指向关联的构造函数,使用构造函数建立对象:
html
function Person() { } var person = new Person(); person.name = "Kevin"; console.log(person.name); // "Kevin"
Person就是一个构造函数,咱们使用 new
建立了一个实例对象 person。
java
prototype
每一个函数都有一个prototype
属性
每个JavaScript对象(null
除外)在建立的时候就会与之关联另外一个对象,这个对象就是咱们说的原型,每个对象都会从原型“继承”属性。
angularjs
function Person() { } //注意:prototype是函数才会有的属性 // 而__proto__是对象才会有的属性 Person.prototype.name = "Kevin"; var person1 = new Person(); var person2 = new Person(); console.log(person1.name); // "Kevin" console.log(person2.name); // "Kevin"
proto
函数
function Person() { } var person = new Person(); console.log( person.__proto__ === Person.prototype ); // true
constructor
ui
function Person() { } console.log( Person === Person.prototype.constructor ); // true
理解原型和原型链的前提是,弄清楚这里面一共有多少个概念,以及概念和概念之间的关系。.net
这里面涉及到的概念有:原型、原型对象、构造函数、对象(实例)、prototype、proto、constructor。prototype
他们之间的关系是怎样的呢?指针
new
一个这个构造函数的实例对象的时候,这个实例就是咱们说的对象(实例),它具备 proto 属性;new
出来的对象,也就是函数对象而存在的,它具备prototype
属性;contructor
属性(或者叫作指针),它指向关联的构造函数。参考连接:
https://www.jianshu.com/p/be7c95714586
https://blog.csdn.net/xiaotao_css/article/details/72782416
https://blog.csdn.net/shuixiou1/article/details/81048816
http://www.javashuo.com/article/p-ewefmcnc-bv.html
http://www.javashuo.com/article/p-btstweuf-bs.html
https://www.jianshu.com/p/08c07a953fa0
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Inheritance_and_the_prototype_chain
https://blog.csdn.net/lyt_angularjs/article/details/100729591
http://www.javashuo.com/article/p-xihyuaei-ek.html
http://www.javashuo.com/article/p-btstweuf-bs.html
https://zhuanlan.zhihu.com/p/23090041?refer=study-fe
https://www.jianshu.com/p/dee9f8b14771
http://www.javashuo.com/article/p-cenbrctd-bu.html
http://www.javashuo.com/article/p-gcxbntmz-u.html
https://zhuanlan.zhihu.com/p/22787302