在javascript中简单定义一个类class

如下定义一个Student的类。里面有name和age两个属性和方法。
function Student(){
this.name = "abc";
this.age = 16;

this.getName = function(){
return this.name;
}
this.getAge = function(){
return this.age;
}
}

使用

var s = new Student();
alert( s.getName() );
alert( s.getAge() );
posted on 2008-04-29 22:34  Kwongwah  阅读(185)  评论(0编辑  收藏  举报