随笔 - 48, 文章 - 0, 评论 - 0, 阅读 - 12391
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
复制代码
 
<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> 
复制代码

 

点击右上角即可分享
微信分享提示