function Grand() {
this.money = 20000;
}
Grand.prototype.last = 'zh';
var grand = new Grand();
function Father() {
this.height = '2m';
}
Father.prototype = grand;
var father = new Father();
function Me() {
this.jineng = 'IT';
}
Me.prototype = father;
var me = new Me();
console.log(grand);
// Grand { // = grand
// money : 20000,
// __proto__ : { // = Grand.prototype
// last : 'zh',
// constructor : Grand,
// __proto__ : {...}
// }
// }
console.log(father);
// Grand { // = father
// height : '2m',
// __proto__ : Grand { // = grand (Father.prototype)
// money : 20000,
// // (无constructor)
// __proto__ : { // = Grand.prototype
// last : 'zh',
// constructor : Grand,
// __proto__ : {...}
// }
// }
// }
console.log(me);
// Me { // = me
// jineng : 'IT',
// __proto__ : Grand { // = father (Son.prototype)
// height : '2m',
// // (无constructor)
// __proto__ : Grand { // = grand (Father.prototype)
// money : 20000,
// // (无constructor)
// __proto__ : { // = Grand.prototype
// last : 'zh',
// constructor : Grand,
// __proto__ : {...}
// }
// }
// }
// }
var a = {}; // 相同结果: var a = new Object();
console.log(a);
// {
// __proto__ : {...} // = Object.prototype // 里面再无 __proto__ 属性,即原型链最末端
// }
js 原型链_练习
最新推荐文章于 2022-11-15 17:20:37 发布