javascript封装简单实现方法
本文实例讲述了javascript封装简单实现方法。分享给大家供大家参考。具体如下:
varPerson=function(name,gender,age){
this.Name=name;
this.Gender=gender;
this.Age=age;
this.SetName=function(sname){
this.Name=sname;
}
this.GetName=function(){
returnthis.Name;
}
this.SetGender=function(sgender){
this.Gender=sgender;
}
this.GetGender=function(){
returnthis.Gender;
}
};
/*
静态公用方法
*/
Person.Play=function(){
alert("这是一个静态方法");
}
/*
Javascript规定,每一个构造函数都有一个prototype属性,指向另一个对象。这个对象的所有属性和方法,都会被构造函数的实例继承。
这意味着,我们可以把那些不变的属性和方法,直接定义在prototype对象上。
*/
Person.prototype.Address="中华人民共和国";
Person.prototype.SayHello=function(){
alert(Person.prototype.Address);
}
希望本文所述对大家的javascript程序设计有所帮助。
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短