在Chrome控制台中展开JavaScript对象时,会显示不同的属性值 [英] Different property value is displayed when javascript object is expanded in Chrome console

查看:186
本文介绍了在Chrome控制台中展开JavaScript对象时,会显示不同的属性值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Chrome开发工具进行一些JavaScript调试,发现以下奇怪。



当JavaScript对象扩展时,该日期有可能会有所不同?



解决方案

打印对象时,您应该小心Chrome控制台。请注意,chrome在打印/扩展对象时进行评估,并且它会异步执行(意味着其他代码可能在此期间执行并更改对象)。总是尝试打印到String进行调试,而不是打印对象本身。



我做了一个非常简单的例子来说明问题。

 < div id =foo>< / div> 

console.log($('#foo')); // expect output [div#foo ...]
$('#foo')。attr('id','hello');

Chrome控制台中的实际输出是:





自己尝试这里(JSFiddle)


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屋!

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