开发者

Paul Irish's log.history [closed]

开发者 https://www.devze.com 2023-02-28 02:32 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
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

精彩评论

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