VS Code调试js

[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())
  1. VS Code ->帮助->切换开发人员工具,打开调试开发人员工具视图


    VS Code调试js_第1张图片
  2. 选择console,点击shift+enter可以进行多行编辑,此时把右边的代码,复制粘进去,可以看到运行结果(这里用的是console,当然也可一用alert)。


    VS Code调试js_第2张图片

你可能感兴趣的:(VS Code调试js)