我有三個構造函數。學校,教師和學生。 到目前爲止,我的代碼中的所有內容都感覺很好,但我似乎無法在teacher.prototype中獲得兩個函數來響應。我是新來的js,我試圖瞭解爲什麼這是不響應我不能讓我的原型在我的構造函數中做出反應
//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 = student;
this.classroom = [],
this.detention = []
}
//create a constructor for teachers and students
//link them all together
function teacher(admin,name){
this.admin = admin
this.name = name
admin = true
//inherit some of the properties of school
}
function student(fname,lname,year,average){
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.unshift(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 top = new student("topanga","lawrence",10,43)
shaun.learn();
你是如何初始化學校的? – karthick