博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
 
<script type="text/javascript"> 
/* 
示例用一个对象组合表示学校中的课程 
'Lecture'类 
用name和teacher作为参数 
*/ 
function Lecture(name,teacher){ 
this.name=name; 
this.teacher=teacher; 
} 
//'Lecture'类的一个方法,用于生成一条信息 
Lecture.prototype.display=function(){ 
return this.name + " 是教 "+this.teacher +" 的。" ; 
} 
//下面用new来构造一个新的函数,然后调用display方法 
var L = new Lecture("李老师","英语"); 
var L_msg = L.display(); 
alert(L_msg); 
</script>