简体   繁体   English

在Chrome控制台中调试javascript

[英]debugging javascript in Chrome console

I inserted quite a few console.log(); 我插入了相当多的console.log(); statements in a javascript program (written by someone else) and went to view the results in Chrome console. javascript程序中的语句(由其他人编写)并在Chrome控制台中查看结果。 You'll see from the image in this post that three of the lines have numbers inside of them (32, 8, and 8). 你会从这篇文章的图片中看到,其中三行中有数字(32,8和8)。 Those numbers are not clickable. 这些数字不可点击。 The console is only showing a few of the console.log statements, so I'm guessing those numbers are referring in some way to the other statements not displayed. 控制台只显示了一些console.log语句,所以我猜这些数字在某种程度上是指未显示的其他语句。 This is the first time that I've seen that happen, although I've done this same thing before (inserted a lot of console.log statements). 这是我第一次看到这种情况发生,虽然我之前做过同样的事情(插入了很多console.log语句)。

1) does the fact that it's not showing all the console log statements mean something significant? 1)它没有显示所有控制台日志语句意味着重要的事实吗? 2) is there some way to understand what those numbers mean, and why they're shown? 2)有什么方法可以理解这些数字的含义,以及它们为何被展示出来?

在此输入图像描述

Nothing significant. 没什么重要的。 It's just that Google Chrome's console is smart enough to group identical lines and update the counter indicating how many repetitions there were, instead of printing each identical log in a new line. 只是谷歌Chrome的控制台足够聪明,可以将相同的行分组并更新计数器,指示有多少重复,而不是在新行中打印每个相同的日志。

For example, if you have the following loop: 例如,如果您有以下循环:

for (var i = 0; i < 100; i++) {
    console.log("a");
}​

Chrome's console will show a single line with (100) a , whilst others, such as Internet Explorer's Developer Tools, will print a a hundred times. Chrome的控制台将显示一个单行(100) a ,而其他人,如Internet Explorer的开发工具,将打印a百倍。

Those are repeat occurrences of the same thing being logged, on the same line of code, in quick succession. 这些是在同一行代码中快速连续记录同一事件的重复出现。 So you logged it 32 times, then a little later you logged it 8 more times, then 8 more times again. 所以你记录了32次,稍后再记录8次,然后再记录8次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM