js面向对象(2)----原型链的继承

下面介绍的原型链的继承是指构造函数通过 对象的prototype 属性来完成的继承

 

//构造函数的通过prototype 的原型链继承

function man(){
this.human='中国人'
}

function person(name,age){
this.name=name
this.age=age
}

person.prototype=new man()//改变person的prototype 



person.prototype.constructor=person //这里有个bug 声明后的prototype 会继承man的constructor 为了保持回溯的正常 在这里再声明一次

var person1=new person()

var man1=new man()

console.log(person1.constructor) //person
console.log(man1.constructor) //man

console.log(person1.human)//中国人

 


 

posted @ 2017-11-22 16:53  missmz  阅读(159)  评论(0编辑  收藏  举报