var attendance={
students:[],
total:6,
join:function(name){
this.students.push(name)
console.log(this.students)
if(this.students.length===this.total){
console.log(name+"到课,学生已经全部到齐")
}else{
console.log(name+"到课,学生已经未到齐")
}
},
leave:function(name){
var idx=this.students.indexOf(name)
if(idx!==-1){
this.students.splice(idx,1)
}
console.log(name+"早退")
console.log(this.students)
}
}
attendance.join("歌谣")
attendance.join("方方")
attendance.join("康康")
attendance.leave("轩轩")
运行结果