//创建一个student对象
function student(name,sex)
{
this.name=name;
this.sex=sex;
}
//实例化对象
function Test(){
var objtest=new student('姓名','性别');
alert("姓名:"+objtest.name+",性别"+objtest.sex);
}
//给student添加一个方法
student.prototype.getInfo=function(){
return "姓名:"+this.name+",性别"+this.sex;
}
等价于:
function student(name,sex)
{
this.name=name;
this.sex=sex;
this. getInfo=function(){
return "姓名:"+this.name+",性别"+this.sex;
}