var animal=function(name){ //构造函数
this.name=name;
this.sayhello=function(){
alert("hi我是"+this.name);
};
}
animal.prototype.shout=function(){ //prototype主要作用:给类增加一个新的属性或函数
alert(this.name+"正在叫!");
};
animal.prototype.game=function(){
alert(this.name+"正在玩耍!");
};
var dog=new animal("小黑"); //实例化
dog.sayhello();
dog.shout();
dog.game();
var animal=function(name){
this.name=name;
this.sayhello=function(){
alert("hi我是"+this.name);
};
}
animal.prototype.shout=function(){
alert(this.name+"正在叫!");
};
animal.prototype.game=function(){
alert(this.name+"正在玩耍!");
};
var Dog=function(name){
this.name=name;
this.shout=function(){ //重写父类的函数
alert(this.name+"汪汪叫!");
}
}
Dog.prototype=Cat.prototype=new animal();
var dog=new Dog("小黑");
dog.sayhello();
dog.shout();
dog.game();
var cat=new Cat("小白");
cat.sayhello();
cat.shout();
cat.game();
var animal=function(name){
this.name=name;
this.sayhello=function(){
alert("hi我是"+this.name);
};
}
Function.prototype.extends=function(superclass){ //extends是保留关键字,不能拿出来单独使用,如var extends=function(){},而这里可以使用是因为他做为函数的属性添加上去
this.prototype=new superclass();
};
animal.prototype.shout=function(){
alert(this.name+"正在叫!");
};
animal.prototype.game=function(){
alert(this.name+"正在玩耍!");
};
var Dog=function(name){
this.name=name;
this.shout=function(){
alert(this.name+"汪汪叫!");
}
}
Dog.extends(animal);
var dog=new Dog("小黑");
dog.sayhello();
dog.shout();
dog.game();
var dog=new Dog("小白");
dog.sayhello();
dog.shout();
dog.game();
var animal=function(name){
this.name=name;
this.sayhello=function(){
alert("hi我是"+this.name);
};
}
animal.prototype.shout=function(){
alert(this.name+"正在叫!");
};
animal.prototype.game=function(){
alert(this.name+"正在玩耍!");
};
var Dog=function(name){
animal.call(this,name);
}
var dog=new Dog("小黑");
dog.sayhello();
dog.shout();
dog.game();
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有