我在打电话:
console.log(some_random_object);
…Chrome可以将对象有效地转储到控制台中。很好,因为我可以看到很多有用的东西,但有时我想实际使用该对象,以查看它如何在控制台中响应某些内容。
有什么方法可以将先前
console.log
的对象分配给变量,以便我可以开始使用它了吗? 最佳答案
对console.log()
使用包装器:
function log() {
window.logHistory = window.logHistory || [];
if (console) {
window.logHistory.push(arguments);
console.log.apply(console, arguments);
}
}
log("Test");
log({
test: 1,
team: "Abc"
});
log(window.logHistory);
演示:http://jsfiddle.net/pratik136/DY4Sk/
输出: