js继承
时间:2014-09-04 18:56:19
收藏:0
阅读:247
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=new animal("小黑");
dog.sayhello();
dog.shout();
dog.game();
评论(0)