如何在Safari中更改console.log的默认行为? [英] How can I change the default behavior of console.log in Safari?
问题描述
在没有附加组件的Safari中, console.log
将显示最后执行状态的对象,而不是控制台时的状态.log
被调用。
In Safari with no add-ons, console.log
will show the object at the last state of execution, not at the state when console.log
was called.
我必须克隆对象只是为了通过 console.log $输出它c $ c>获取该行的对象状态。
I have to clone the object just to output it via console.log
to get the state of the object at that line.
示例:
var test = {a: true}
console.log(test); // {a: false}
test.a = false;
console.log(test); // {a: false}
推荐答案
我想你了重新寻找 console.dir()
。
console.log()
没有做你想要的,因为它打印了对象的引用,当你弹出它时,它就被改变了。 console.dir
在您调用它时打印对象中属性的目录。
console.log()
doesn't do what you want because it prints a reference to the object, and by the time you pop it open, it's changed. console.dir
prints a directory of the properties in the object at the time you call it.
JSON的想法下面是一个很好的;你甚至可以继续解析JSON字符串并获得一个可浏览的对象,比如.dir()会给你:
The JSON idea below is a good one; you could even go on to parse the JSON string and get a browsable object like what .dir() would give you:
console.log( JSON.parse(JSON.stringify(obj)));
这篇关于如何在Safari中更改console.log的默认行为?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!