先创建一个函数:
function Student(){
}
//添加静态方法
Student.getSingleStudent=function(){
if(Student.prototype.lock==='undefinde'){
Student.prototype.singInstance=new Student;
Student.prototype.lock=true;
}
return Student.prototype.singInstance;
}
var student1=Student.getSingleStudent();
var student2=Student.getSingleStudent();
alert(student1===student2)
弹出true