Javascript 调用我的对象时,我的数组没有显示正确的值
所以我有一个学校,老师,学生的作业。我让它工作只是当我把“学生”送到拘留所或教室时,它没有在数组中显示正确的值Javascript 调用我的对象时,我的数组没有显示正确的值,javascript,Javascript,所以我有一个学校,老师,学生的作业。我让它工作只是当我把“学生”送到拘留所或教室时,它没有在数组中显示正确的值 //create a constructor for a school that has all teachers and students function school(principal,teacher,student,classroom,detention){ this.principal = principal, this.teacher = teacher,
//create a constructor for a school that has all teachers and students
function school(principal,teacher,student,classroom,detention){
this.principal = principal,
this.teacher = teacher,
this.student = [],
this.classroom = [],
this.detention = []
}
//create a constructor for teachers and students
//link them all together
function teacher(admin,name){
school.call(this)
this.admin = admin
this.name = name
admin = true
}
function student(fname,lname,year,average){
teacher.call(this);
this.fname = fname,
this.lname = lname,
this.year = year,
this.average = average
}
teacher.prototype = Object.create(school.prototype);
//teacher can send students to class
teacher.prototype.learn = function(student){
this.classroom.unshift(student)
}
//be able to move students to detention
teacher.prototype.punish = function(student){
this.detention.push(student)
}
//be able to view full details of each student.
student.prototype = Object.create(teacher.prototype)
student.prototype.fullDetails = function(){
return this.fname + ' ' + this.lname + " is in " + this.year + 'th' + ' grade and his average is ' + this.average;
}
var mr_feeney = new teacher(true,"Mr.Feeney")
var corey = new student("corey","mathews",10,88)
var shaun = new student("shaun","hunter",10,43)
var topa = new student("topanga","lawrence",10,43)
mr_feeney.learn();
shaun.learn();
corey.learn();
topa.learn();
//IMPORTANT: arrays not showing proper values in the console log
我对JavaScript还是相当陌生,所以我不会在控制台中返回任何错误。我似乎无法准确指出这段代码中到底遗漏了什么或错了什么
我理解我的代码的层次结构没有意义。作业的目的是能够将学生发送到教室阵列或拘留阵列。通常使用标题大小写,例如
教师
,学生
,以及学校
。您能告诉我们您正在记录的阵列吗,他们的价值观是你想要的吗?你的等级制度毫无意义。教师如何成为一所学校?学生如何成为老师?另外,为什么要修改构造函数的局部参数?对于这一点,学生是如何成为教师的?作为初学者,我们对OOP的努力表示赞赏,但这段代码肯定有一些问题。通常使用标题大小写来编写类,例如教师
,学生
,和学校
。您能告诉我们您正在记录哪些数组,它们的值是您想要的吗?您的层次结构毫无意义。教师如何成为一所学校?学生如何成为老师?还有,为什么要修改构造函数的局部参数?对于这一点,学生怎么会是老师?作为一个初学者,我们对OOP中的努力投了赞成票,但这段代码肯定有一些问题。