1.1 강의와 강의 일정을 표현하는 객체지향 자바스크립트 코드
<script type="text/javascript">
function Lecture(name, teacher){
this.name = name;
this.teacher = teacher;
}
Lecture.prototype.display = function (){
return this.teacher + " is teaching " +this.name;
};
// 강의 목록을 담은 배열을 인자로 받는 Schedule 생성자
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() + "\n";
}
return str;
};
var mySchedule = new Schedule([
new Lecture("Oracle", "oramaster"),
new Lecture("Java", "javamaster"),
new Lecture("JavaScript", "jsmaster")
]);
//Schedule정보를 출력한다.
alert(mySchedule.display());
</script>