https://juejin.im/post/6844903477819211784
1.原型链继承
function Parent () {
this.name = 'kevin';
}
Parent.prototype.getName = function () {
console.log(this.name);
}
function Child () {
}
Child.prototype = new Parent();
var child1 = new Child();
console.log(child1.getName()) // kevin
缺点:
-
引用类型的属性被所有实例共享
image.png
- 在创建 Child 的实例时,不能向Parent传参
2.借用构造函数(经典继承)
缺点:
方法都在构造函数中定义,每次创建实例都会创建一遍方法。




-
寄生组合式继承
image.png
image.png
image.png
网友评论