----------------------------方法一----------------------------------
//定义类
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());
posted on 2007-03-13 17:14  HenryZhang  阅读(355)  评论(0编辑  收藏  举报