Function、Object、Prototype 之間的關係解析

前提:js中全部的內置對象都是Function 的實例。 spa

  例如:Array\String\Number... 等prototype

 

原理剖析:code

  對象屬性搜索的原理就是按照對象的 __proto__ 屬性進行搜索,直到__proto__=null 中止搜索對象

 1 > Array.__proto__
 2 < function () {}
 3 
 4 >var arr =[]
 5 >arr.__proto__==Array.prototype
 6 <true
 7 
 8 >Function.prototype
 9 <function () {}
10 
11 >Function.__proto__
12 <function () {}
13 
14 >Function.__proto__.__proto__
15 <Object {}
16 
17 >Function.__proto__.__proto__==Object.prototype
18 <true
相關文章
相關標籤/搜索