私は3つのコンストラクタを持っています。学校、教師、学生。 これまでのところ私のコードのすべては大丈夫だと感じましたが、私はteacher.prototype内で2つの関数を返すようには思えません。私は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