- 构造函数继承
function Person(name){
this.name=name;
}
function Child(){
Person.call(this,'wang')
this.age=16
}
var man=new Child();
console.log(man.name,man.age)
- 原型构造函数组合继承
function Person(name){
this.name=name;
}
Person.prototype.sayName=function(){
alert(this.name)
}
function Child(name,age){
Person.call(this,name);
this.age=age;
}
Child.prototype=new Person();
Child.prototype.constructor=CHild;
var instance=new Child('lisi',18)
网友评论