__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