原型链继承

耗尽温柔 提交于 2019-11-26 13:21:35

和原型继承有什么不同呢?
分别的用处是什么呢?
需要仔细体会

function Parent() {
    this.name = 'mike';
}

function Child() {
    this.age = 12;
}

Child.prototype = new Parent();
let child1 = new Child();

console.log(child1.age);
console.log(child1.name);

function Brother() {
    this.weight = 60;
}

Brother.prototype = new Child();
let brother1 = new Brother();

console.log(brother1.weight);
console.log(brother1.age);
console.log(brother1.name);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!