构造函数
案例:
function flower(name,genera,uses){
this.name = name;
this.genera = genera;
this.uses = uses;
this.showName = function(){
alert(this.name)
}
}
原型对象
案例:
function Flower(){
}
Flower.prototype.name ="玫瑰"
Flower.prototype.genear = "你好"
Flower.prototype.uses= "观赏"
Flower.prototype.showName = function(){
alert(this.name)
}
借用父类无参构造函数
案例:
function Humans(){
this.clothing = ["trousers","dress","jacket"];
}
function Man(){
Humans.call(this); //继承了Humans
}
组合继承
案例:
function Humans(name){
this.name = name;
this.clothing = ["trousers","dress","jacket"]; //数组
}
Humans.prototype.sayName = function(){
alert(this.name);
}
function Man(name,age){
Humans.call(this,name); //继承属性
this.age = age;
}
Man.prototype = new Humans(); //继承方法
Man.prototype.sayAge = function(){
alert(this.age);
}