Firebug在其命令行中执行代码时打印一个附加数字

时间:2015-06-01 10:52:00

标签: javascript firebug

我在Firebug的控制台中执行JavaScript。在运行以下循环时,我注意到它打印了一个额外的数字:

var i = 0; 

while(i<10) {
  console.log(i);
  i++;
}

它提供以下输出:

var i = 0;   while(i<10) {   console.log(i);   i++; } 
0
1
2
3
4
5
6
7
8
9
9

这是一个错误还是别的什么?

2 个答案:

答案 0 :(得分:0)

造成干扰的最后一个9console.log()的返回值。请尝试使用alert(i)代替console.log(i)

答案 1 :(得分:0)

Console panel输出通过Command LineCommand Editor执行的脚本的返回值。不幸的是,Firebug在视觉上无法区分通过Sub myModule() Dim i As Long Dim j As Long Dim k As Long Dim cNum As cNum Dim cDpo As cDpo Dim cQty As cQty Dim oNum As Collection Dim oDpo As Collection Dim oQty As Collection Set oNum = New Collection For i = 1 To 3 Set cNum = New cNum cNum.FileName = "File " & i Set oDpo = New Collection For j = 1 To 3 Set cDpo = New cDpo cDpo.Qty = "Qty" & i & j cDpo.Delivery = "Delivery " & i & j Set oQty = New Collection For k = 1 To 3 Set cQty = New cQty cQty.Statut = "OK_" & i & "-" & j & "-" & k oQty.Add cQty Next k Set cDpo.QtyAdd = oQty oDpo.Add cDpo Next j Set cNum.DpoAdd = oDpo oNum.Add cNum Next i 'Set oDpo = Nothing ' For Each cNum In oNum Debug.Print "" Debug.Print "---------FILE ----------------" Debug.Print "" Debug.Print "-[NUM] " & cNum.FileName & " | " & cNum.Info Set oDpo = cNum.Dpo For Each cDpo In oDpo Debug.Print "--[DPO] " & cDpo.Counterpart & " | " & cDpo.Delivery Set oQty = cDpo.Qty For Each cQty In oQty Debug.Print "---[QTY] " & cQty.Quantity & " | " & cQty.Statut Next Next Next End Sub 创建的输出的返回值。所以输出结尾的第二个console.log()是返回值 在Firefox built-in DevTools中,这更为明显:

Display of return value of command line expression in built-in DevTools

请注意,无法抑制返回值的输出。