首页 > Web开发 > 详细

js继承

时间:2014-09-04 18:56:19      阅读:257      评论:0      收藏:0      [点我收藏+]
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();

js继承

原文:http://www.cnblogs.com/zhangwenkan/p/3956620.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!