开发者

Paul Irish's log.history [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

I don't understan开发者_JAVA技巧d how to use log.history in Paul Irish's lightweight wrapper for console.log.


Just include the JS in your page. Something like this:

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))}};

This gives you a reverse-chronological history of everything that's been logged, stored in log.history. Want to see the first thing logged?

> log.history[0]

Want to the the last thing logged?

> log.history.slice(-1)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜