js __proto__

前端之家收集整理的这篇文章主要介绍了js __proto__前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  1. 构造函数的__proto__

 function Animal(){

}
var anim = new Animal();

Object.__proto__===Function.prototype //true
Array.__proto__===Function.prototype //true
Animal.__proto__===Function.prototype //true

Function.prototype===Function //false
Function.prototype.constructor===Function //true

Object Array Animal都是由Function new出来的,所以他们的__proto__都指向Function.prototype

Function.prototype上面挂载的有bind call apply toString等方法

  1. 普通对象

anim.__proto__===Animal.prototype //true

Animal.prototype.proto===Object.prototype //true
Object.prototype.proto===null; //true
--> anim.proto.proto.proto===null

var dog={};
dog.proto===Object.prototype //true
Object.prototype.proto===null //true
-->dog.proto.proto===null //true

每个普通对象的__proto__都指向其构造函数的prototype

每个对象的__proto__都指向其构造函数的prototype(除了Object.prototype.__proto__===null //true)

dog与anim相比,少了一层__proto__

Js中Prototype、__proto__、Constructor、Object、Function关系介绍

猜你在找的程序笔记相关文章