JavaScript里万物皆对象,但是对象之间的关系异常复杂和混乱,所以决定花时间把他们之间的核心关系搞清楚,并制作成图,分享出来,了解了这个图,再也不用买步步高点读机了,以下程序在ie11,chrome49,firfox46,opera37下都是true,ie10之前的ie版本访问__proto__会出错。啥也不说了,尽在图和代码中。
<!DOCTYPE HTML>
<html style="height: 100%"><head>
<meta charset="utf-8">
</head>
<body style="height: 100%">
<!--<script type="text/javascript" src="jquery-2.2.3-unzip.js">-->
</script>
<script type="text/javascript" >
function x(){}
var y=new x();
z=new Object();
console.log(y.__proto__==x.prototype,"y.__proto__==x.prototype")
console.log(y.constructor==x,"y.constructor==x")
console.log(z.constructor==Object,"z.constructor==Object")
console.log(z.__proto__==Object.prototype,"z.__proto__==Object.prototype")
console.log(x.constructor==Function,"x.constructor==Function")
console.log(x.prototype.constructor==x,"x.prototype.constructor==x")
console.log(x.prototype.__proto__==Object.prototype,"x.prototype.__proto__==Object.prototype")
console.log(Object.constructor==Function,"Object.constructor==Function")
console.log(Object.prototype.constructor==Object,"Object.prototype.constructor==Object")
console.log(Object.prototype.__proto__==null,"Object.prototype.__proto__==null")
console.log(Function.constructor==Function,"Function.constructor==Function")
console.log((x.__proto__==Object.__proto__)&&(x.__proto__==Function.__proto__)&&(x.__proto__==Function.prototype)&&(Function.__proto__==Object.__proto__)&&(Function.prototype==Object.__proto__)&&(Function.__proto__==Function.prototype),"(x.__proto__==Object.__proto__)&&(x.__proto__==Function.__proto__)&&(x.__proto__==Function.prototype)&&(Function.__proto__==Object.__proto__)&&(Function.prototype==Object.__proto__)&&(Function.__proto__==Function.prototype)");
console.log(x.__proto__.prototype==undefined,"x.__proto__.prototype==undefined")
console.log(x.__proto__.__proto__==Object.prototype,"x.__proto__.__proto__==Object.prototype")
console.log(x.__proto__.constructor==Function,"x.__proto__.constructor==Function")
最后奉上我画了无数次才画成的手稿,纪念一下,原稿已经不知道哪去了,想想应该收藏起来的。
</script>
</html>