javascript 面向对象的经典实例代码

  作者:bea

<script language="javascript"><!-- function Lecture(name,teacher){ this.name=name; this.teacher=teacher; } Lecture.prototype.display=function(){ return this.teacher+"正在教幼儿园"+this.name+""; } function Schedule(l


<script language="javascript"><!--
function Lecture(name,teacher){
this.name=name;
this.teacher=teacher;
}
Lecture.prototype.display=function(){
return this.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("语文","熊老师"),
new Lecture("数学","钟老师")
]);
alert(mySchedule.display());
// --></script>




[Ctrl+A 全选 注:
如需引入外部Js需刷新才能执行]

JavaScript面向对象编程

http:///article/13661.htm


有用  |  无用

猜你喜欢