简体   繁体   English

console.log / console.dir显示对象的最后状态,而不是当前状态

[英]console.log/console.dir showing last state of object, not current

I want to log how my array/object is changing with new steps of loop. 我想用新的循环步骤记录我的数组/对象是如何变化的。 Console.log does this bad. Console.log做得不好。 It shows only last state of object everywhere. 它只显示对象的最后状态。 For example: 例如:

var a = {};
console.log(a); // {bob1: 0, bob2: 0}
a.bob1 = 0;
console.log(a); // {bob1: 0, bob2: 0}
a.bob2 = 0;
console.log(a); // {bob1: 0, bob2: 0}

I found there, on so, another command: console.dir . 我在那里找到了另一个命令: console.dir It is working properly in same example. 它在同一个例子中正常工作。 It shows states of object correcly. 它正确地显示了对象的状态。

Look this example. 看这个例子。 This command works perfect: http://jsfiddle.net/RLzVV/ 这个命令很完美: http//jsfiddle.net/RLzVV/

Now, look my code pls. 现在,看看我的代码吧。 All output is in console. 所有输出都在控制台中。 http://jsfiddle.net/3BDs7/4/ http://jsfiddle.net/3BDs7/4/

This is aStar algorithm. 这是一个星际算法。 Take a look on this part (neighbor 3 loop <--- neighbor 3 start ---> this code is situated here <--- neighbor 3 stop --> ) in console. 在控制台中查看此部分(邻居3循环<--- neighbor 3 start ---> this code is situated here <--- neighbor 3 stop --> )。 Lanes, which output this to console are 105-113 : 车道输出到控制台是105-113

new openset length: 2
openset after adding new vertex
**shows 1 element, but length is 2**

It shows length is 2, but shows only 1 element. 它显示长度为2,但仅显示1个元素。 But! 但! Seems to me algo is working correctly (it is popping another element, which is hidden on this step after). 在我看来algo工作正常(它弹出另一个元素,之后隐藏在此步骤中)。 Why this bug appears? 为什么会出现这个bug? Did I did something wrong? 我做错了什么吗? Seems to me, everywhere only last state of array shown, not current:( help me please. 在我看来,到处都是阵列显示的最后状态,而不是当前:(请帮帮我。

That's a known issue -- sounds like you are running under Chrome. 这是一个已知问题 - 听起来像是在Chrome下运行。

The easiest work-around is to JSON encode the value as you log in. 最简单的解决方法是在登录时对值进行JSON编码。

console.log(JSON.stringify(a));

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

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