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

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

问题描述

If you execute this code:

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

Is there a workaround for logging objects in Chrome?

解决方案

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.

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天全站免登陆