<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>原型链</title>
<script>
// 1. es5 构造函数
function Star(uname, uage) {
this.uname = uname;
this.uage = uage;
}
// 字面量
Star.prototype = {
constructor: Star,
read: function() {
console.log('can to read!');
return 'test';
},
speak: function() {
console.log('go to speak');
},
};
var zzh = new Star('zzh', '37');
console.log(zzh.uname);
zzh.read();
// console.log(zzh.__proto__);
console.log(zzh.__proto__ === Star.prototype); // 对象原型 __proto__
// console.log(Star.prototype); // Star的原型对象prototype , 共享方法
console.log(Star.prototype); // 有一个 对象原型 __proto__ 指向Object
console.log(Star.prototype.__proto__); // Object 原型对象
console.log(Star.prototype.__proto__.constructor);
console.log(Star.prototype.__proto__.constructor.prototype);
console.log(Star.prototype.__proto__.__proto__); //Object原型对象指向null
</script>
</head>
<body>
</body>
</html>
结果图: