如下定义一个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() );
转载于:https://www.cnblogs.com/kwongwah/archive/2008/04/29/1176915.html