在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() );
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() );