function Lecture(name, teacher) {
this.name = name;
this.teacher = teacher;
} Lecture.prototype.display = function () {
return this.teacher + " is teacher " + this.name;
} function Schedule(lectures) {
this.lectures = lectures;
} Schedule.prototype.display = function () {
var str = "";
for (var i = 0; i < this.lectures.length; i++) {
str += this.lectures[i].display + " ";
}
return str;
}
var mySchedule = new Schedule([new Lecture("Gym", "Mr.Smith"), new Lecture("Math", "Mr.Jones"), new Lecture("English", "TBD")]); alert(mySchedule.display());
请大家看上面有哪里错啦

解决方案 »

  1.   


    Schedule.prototype.display = function () {
            var str = "";
            for (var i = 0; i < this.lectures.length; i++) {
                str += this.lectures[i].display() + " ";
            }
            return str;
        }
      

  2.   

    display()
      

  3.   

    貌似:
     Schedule.prototype.display = function () {
            var str = "";
            for (var i = 0; i < this.lectures.length; i++) {
                str += this.lectures[i].display + " ";
            }
            return str;
        }改为:
     str += this.lectures[i].display() + " ";看看