function?

fuyou001 2008-05-20 08:58:22
//类Lecture的构造器
//使用两个字符串参数,name和teacher
function Lecture( name, teacher ) {
//把它们作为对象的本地属性保存
this.name = name;
this.teacher = teacher;
}
//类Lecture的方法,生成一个显示该课程信息的字符串
Lecture.prototype.display = function(){
return this.teacher + " is teaching " + this.name;
};
//类Schedule的构造器
//使用一个lectures类型的数组作为参数
function Schedule( lectures ) {
this.lectures = lectures;
}
//类Schedule的方法,用来构造一个描述该课程表的字符串
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([
//创建一个课程对象的数组,
//作为传给课表(原文此处为Lecture,疑为笔误)对象的唯一参数
new Lecture( "Gym", "Mr. Smith" ),
new Lecture( "Math", "Mrs. Jones" ),
new Lecture( "English", "TBD" )
]);
// 弹出对话框显示课表的信息
alert( mySchedule.display() );

有点看不明白 :[
//创建一个课程对象的数组,
//作为传给课表(原文此处为Lecture,疑为笔误)对象的唯一参数
new Lecture( "Gym", "Mr. Smith" ),
new Lecture( "Math", "Mrs. Jones" ),
new Lecture( "English", "TBD" )
];这数组吗?我到网上没找有这种声明方式!这是什么意思
...全文
64 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
王集鹄 2008-05-20
  • 打赏
  • 举报
回复
[1, 2, 3, 4] 这个该知道了吧。。。声明数组

var object = new Lecture( "Gym", "Mr. Smith" ); 这个也知道吧。。。构造对象

拼在一起就不知道了???[img=http://p.blog.csdn.net/images/p_blog_csdn_net/zswang/%E7%80%91%E5%B8%83%E6%B1%97.gif]图[/img]
fuyou001 2008-05-20
  • 打赏
  • 举报
回复
。。。“[new... ]”对象的数组。。。?这怎么理解?
王集鹄 2008-05-20
  • 打赏
  • 举报
回复
“[ ]”就是声明一个数组。。。“[new... ]”对象的数组。。。

注释已经说得很清楚了。。。[img=http://p.blog.csdn.net/images/p_blog_csdn_net/zswangii/%E6%B7%AB%E7%AC%91.gif]图[/img]
fuyou001 2008-05-20
  • 打赏
  • 举报
回复
在线等

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧