首页 > 其他 > 详细

[Debug] Debugger Statements

时间:2019-05-22 00:41:27      阅读:105      评论:0      收藏:0      [点我收藏+]

For example you have the following code;

function reverse(str) {
  let reversed = "";
  for (let char of str) {
    reversed = char + reversed;
  }
  return reversed;
}

module.exports = reverse;

 

If you want to debug is in Node, you can do:

function reverse(str) {
  let reversed = "";
  for (let char of str) {
    debugger; // add debugger
    reversed = char + reversed;
  }
  return reversed;
}

reverse("awefw"); // call the function 

module.exports = reverse;

 

Then in cmd, run:

node inspect index.js

技术分享图片

 

Then just type ‘continue‘ or just ‘c‘.

 

It will pause on liine of ‘debugger;‘ Now for example you want to see, what is the variable ‘str‘:

 

you can type: ‘repl‘:

技术分享图片

 

Then after you enter ‘str‘, you will see the output.

[Debug] Debugger Statements

原文:https://www.cnblogs.com/Answer1215/p/10903372.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!