原型链
作者:
智多牛 | 来源:发表于
2016-12-15 15:46 被阅读0次 /**
* 父函数
*/
function People(){}
People.prototype.age = '12';
/**
* 子函数
*/
function Man(){};
Man.prototype = new People();
Man.prototype.constructor = People
/**
* 应用
*/
var man = new Man();
console.log(man.age) //输出:12
/**
* 原型链
*/
console.log(man.__proto__) //输出:People {}
console.log(man.__proto__.age) //输出:12
console.log(man.__proto__.__proto__) //输出:Object {age: "12"}
console.log(man.__proto__.__proto__.age) //输出:输出:12
本文标题:原型链
本文链接:https://www.haomeiwen.com/subject/dikgmttx.html
网友评论