----------------------------方法一----------------------------------
//定义类
function StudentObject(){
//Property
this.Name = "";
this.Age = "";
this.Sex = "";
this.Grade = "";
this.Address = "";
this.Phone = "";
//Method
this.tt = ff;
}
//类的方法实现
function ff(){return "my name is " + this.Name;}
//测试
var stobj = new StudentObject();
stobj.Name = "Henry";
alert(stobj.tt());
//写法2
----------------------------方法二----------------------------------
//定义类
function StudentObject() {
//Property
this.Name = "";
this.Age = "";
this.Sex = "";
this.Grade = "";
this.Address = "";
this.Phone = "";
}
//Mothod
StudentObject.prototype = {
tt: function() {return "my name is " + this.Name + " in tt";},
bb: function() {return "my name is " + this.Name + " in bb";}
}
//测试
var stobj = new StudentObject();
stobj.Name = "dsafdsafdsa";
alert(stobj.tt());
alert(stobj.bb());
转载于:https://www.cnblogs.com/zhanghaibin/archive/2007/03/13/673359.html