1211【js】混合式继承
<h5>原型继承+call</h5>
<p>混合了call方式、原型链方式</p>
<pre><code>//混合式继承 子元素继承父级元素
function Parent(age, color) {
this.age = age;
this.color = color;
}
Parent.prototype.say = function () {
console.log(this.age)
}
function Children(age, color, name) {
Parent.call(this, age, color); //继承父级的年龄,颜色
this.name = name;
}
Children.prototype = new Parent(); //将父级元素的方法继承过来
Children.prototype.sayName = function(){//新增一些方法
alert(this.name);
}
var judy = new Children('18', 'red', 'judy');
console.log(judy)
judy.say();//'18'
judy.sayName();//'judy</code></pre>