为什么Chrome Dev Tools Console以两种不同的方式(单行和多行)生成日志条目?

时间:2017-11-06 00:35:30

标签: javascript google-chrome console.log

以下代码在Chrome开发工具控制台中生成增量单行日志:

var run = function() {
  console.log('hello');
}    
setInterval(run, 250);

enter image description here

当我使用lodash节流包装时,我看到多行日志:

var run = function() {
  console.log('hello');
}
var _run = _.throttle(run, 250);
setInterval(_run, 20);

enter image description here

所有日志条目都链接到两个版本中console.log('hello');的第二个源代码行。为什么存在这种针对节流记录的分裂?

1 个答案:

答案 0 :(得分:0)

相关规范

2.3.2. Printer user experience innovation

  • 重复删除相同的输出以防止垃圾邮件。

    实施例的 在此示例中,实现不仅批处理多个相同的消息,还提供已批处理的消息数。 enter image description here

传递给.log()的示例字符串的变通方法包括将可变数量的空格字符连接到输出,以防止.log()函数识别重复内容

var run = function() {
  console.log("hello".concat(" ".repeat(Math.random() * (1000 - 1) + 1)));
}    
setInterval(run, 250);

使用setTimeout()代替setInterval()

var run = function() {
 console.log("hello");
 setTimeout(run, 250);
}    
setTimeout(run, 250);

或使用console.table()

var run = function() {
  console.table(["hello"]);
}    
setInterval(run, 250);
相关问题