[TOC]
精通javaScript1-1为例:
//'Lecture'类的构造函数
//用名称(name)和教师(teacher)作为参数
function Lecture(name, teacher) {
//
this.name = name;
this.teacher = teacher;
}
Lecture.prototype.display = function () {
return this.teacher + " is teaching " + 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("Gym", "Mr. Smith"),
new Lecture("Gym", "Mr. Smith"),
new Lecture("Gym", "Mr. Smith")
]);
console.log(mySchedule.display())
-
VS Code ->帮助->切换开发人员工具,打开调试开发人员工具视图
-
选择console,点击shift+enter可以进行多行编辑,此时把右边的代码,复制粘进去,可以看到运行结果(这里用的是console,当然也可一用alert)。