保罗爱尔兰的log.history

时间:2011-04-23 19:41:57

标签: javascript

我不明白如何在Paul Irish的lightweight wrapper for console.log中使用log.history。

1 个答案:

答案 0 :(得分:1)

只需在页面中包含JS即可。像这样:

HTML

<html>
    <head>
        <!-- snip -->
        <script src="path/to/console/wrapper.js"></script>
    </head>
    <body><!-- snip --></body>
</html>

的JavaScript

// drop this in the file referenced above
window.log=function(){log.history=log.history||[];log.history.push(arguments);if(this.console){console.log(Array.prototype.slice.call(arguments))}};

这将为您提供已记录的所有内容的反向时间顺序历史记录,存储在log.history中。想看到记录的第一件事吗?

> log.history[0]

想要记录最后一件事吗?

> log.history.slice(-1)