在Chrome中将对象记录到控制台的解决方法 [英] Workaround for logging objects to console in Chrome

查看:140
本文介绍了在Chrome中将对象记录到控制台的解决方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您执行此代码:

var foo = {bar: 'baz'};
window.console.log(foo);
foo.bar = 'bla';

控制台在展开对象后显示:

The console shows this after expanding the object:

(记录物件和阵列,它不是记录的运行时间值)

(when logging objects and arrays, it's not the run-time value that's recorded)

这个错误在一年前被记录了:

This bug was documented over a year ago:

http://code.google.com/p/chromium/issues/ detail?id = 50316

在Chrome中记录对象是否有解决方法?

Is there a workaround for logging objects in Chrome?

推荐答案

我只需要使用 JSON.stringify 。不知道它是否会为你做,但它是容易和有效的调试的目的。

I just use JSON.stringify when i need it. Don't know if it will do it for you, but it is easy and effective for debugging purposes.

这不是对有功能引用的对象tho,所以如果你需要,我会考虑使用对象的一个​​深层副本(你可以使用jQuery的优秀 extend 方法)或滚动你自己的日志功能,循环递归对象并打印出来。

This is no good for objects with function references in it tho, so if you need that i would consider using either a deep copy of the object (you can use jQuery's excellent extend method) or roll you own logging function that will loop recursively over the object and print it out.

这篇关于在Chrome中将对象记录到控制台的解决方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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