加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 创业 > C语言 > 正文

js __proto__

发布时间:2020-12-15 00:29:38 所属栏目:C语言 来源:网络整理
导读:构造函数的__proto__ function Animal(){ } var anim = new Animal(); Object.__proto__===Function.prototype //trueArray.__proto__===Function.prototype //trueAnimal.__proto__===Function.prototype //true Function.prototype===Function //false Fun
  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关系介绍

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读