原型和原型链实现继承

 

原型和原型链,两个类之间实现继承

组合继承(原型继承+构造函数继承,既能解决属性问题又能解决方法问题)

function Person(name,age){

this.name = name;

this.age = age;

}

Person.prototype.play = function(){

    console.log(我爱玩);

}

function Child(name,age,score){

Person.call(this,name,age);

this.score = score;

}

Child.prototype = Object.create(Parent.prototype) 

Child.prototype.constructor = Child

var chil = new Child(‘哈利’,10,100);

chil.play()   //我爱玩

 

参考:

 https://segmentfault.com/a/1190000015216289?utm_source=sf-similar-article

 

posted on 2019-06-11 10:33  yemiaomiao  阅读(105)  评论(0编辑  收藏  举报

导航