在Chrome控制台中展开JavaScript对象时,会显示不同的属性值 [英] Different property value is displayed when javascript object is expanded in Chrome console
问题描述
当JavaScript对象扩展时,该日期有可能会有所不同?
打印对象时,您应该小心Chrome控制台。请注意,chrome在打印/扩展对象时进行评估,并且它会异步执行(意味着其他代码可能在此期间执行并更改对象)。总是尝试打印到String进行调试,而不是打印对象本身。
我做了一个非常简单的例子来说明问题。
< div id =foo>< / div>
console.log($('#foo')); // expect output [div#foo ...]
$('#foo')。attr('id','hello');
Chrome控制台中的实际输出是:
I'm doing some javascript debugging with Chrome dev tools and found the following oddity.
How is it possible that date has a different value when javascript object is expanded?
You should be careful with chrome console when printing objects. Please note that chrome does evaluations when printing / expanding objects as well as it does it asynchronously (meaning other code may execute in the meantime and change the object). Always try to print to String for debugging, rather than printing the object itself.
I made a very simple example to illustrate the problem.
<div id="foo"></div>
console.log($('#foo')); //expected output [div#foo...]
$('#foo').attr('id','hello');
The actual output in the chrome console is:
Try it yourself here (JSFiddle).
这篇关于在Chrome控制台中展开JavaScript对象时,会显示不同的属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!