的console.log()表示用于同一对象属性矛盾值 [英] console.log() showing contradictory values for the same object property

查看:196
本文介绍了的console.log()表示用于同一对象属性矛盾值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我可能要疯了。

我使用的console.log()看到的对象的状态,然后从下一行的同一对象的特定属性做的console.log(),并为每个得到不同的值。

I use console.log() to see the state of an object and then on the next line do a console.log() on a particular property of the same object and get different values for each.

在code我使用的是:

The code i'm using is:

console.log(this.pictures.Items[pic].val);

for(var i in this.pictures.Items[pic].val) {
    console.log("property: %s, value: %s", i, this.pictures.Items[pic].val[i] );
}

和萤火虫输出:

Picture { isLoaded=true, isSelected=false, img_src="imgs/image1.jpg", more...}

property: isLoaded, value: false
...more properties

你可以看到,isLoaded'是真实的记录物体本身,而是虚假的登录时的属性时。

as you can see, 'isLoaded' is true when logging the object itself but false when logging the property.

我曾尝试以防万一以后再次登录该对象,并再次将是真实的。

I have tried logging the object again after just in case, and it is true again.

有谁知道这里发生了什么?

Does anyone know what is happening here?

感谢

推荐答案

我不能完全肯定,如果这是发生了什么事给你或没有,但的console.log()似乎有一些浏览器的一些问题在这里做一个的console.log()上一个值或使用正在改变或在阵列正在迭代的索引变量不并不总是正常工作。

I'm not entirely sure if this is what is happening to you or not, but console.log() seems to have some issues in some browsers where doing a console.log() on a value or using an index variable that is changing or being iterated in an array does not always work properly.

我的猜测是,它有事情做的事情进程边界,也许在被使用或引用实际的对象或索引中的记录前pression的实际评估的延迟,直到时间之间有着越来越整理改变。我见过在Chrome肯定这个问题 - 不知道有关Firefox

My guess is that it has something to do with things getting marshalled between process boundaries and perhaps a delay in the actual evaluation of the logging expression until a time in which the actual object or index being used or referenced has changed. I've seen this issue in Chrome for sure - don't know about Firefox.

您应该能够通过使用字符串数学建立你最终的字符串来解决这一具体问题。如果只有最后的字符串传递给的console.log(),一切都在充分评估,那么这个问题将不会影响输出。

You should be able to work around this particular issue by using string math to build your final string. If only the final string is passed to console.log() where everything is fully evaluated, then this issue would not impact the output.

这篇关于的console.log()表示用于同一对象属性矛盾值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆