Home > php教程 > php手册 > body text

Console Api makes JS debugging simpler and more efficient

WBOY
Release: 2016-09-01 00:00:25
Original
1487 people have browsed it

除了console.log 你还知道其他调试方法吗?

所有Console Api <script type="text/javascript"><br>     console.dir(console);<br> </script>显示简单信息<script type="text/javascript"><br>     console.log('hello world');<br>     console.info('信息');<br>     console.error('错误');<br>     console.warn('警告');<br> </script>   占位符<script type="text/javascript"><br>     console.log('%d-%d-%d,%s',2016,08,21,'中国女排夺的冠军!');<br> </script>   统计代码执行次数<script type="text/javascript"><br>     function getInfo()<br>     {<br>         console.count('执行次数:');<br>     }<br>     getInfo();<br>     getInfo();<br>     getInfo();<br>     getInfo();<br> </script>  显示分组信息<script type="text/javascript"><br>     console.group("第一组信息");<br>         console.log('第一组:自定义消息1');<br>         console.log('第一组:自定义消息2');<br>         console.log('第一组:自定义消息3');<br>     console.groupEnd();<br> <br>     console.group("第二组信息");<br>         console.log('第二组:自定义消息1');<br>         console.log('第二组:自定义消息2');<br>         console.log('第二组:自定义消息3');<br>     console.groupEnd();<br> </script>  显示对象信息<script type="text/javascript"><br>     var TomObj = {<br>         name  : "Tom",<br>         sex   : "男",<br>         age   : '31',<br>         hobby : "coding..."<br>     };<br>     console.dir(TomObj);<br> </script>  显示页面信息<div id="console"><br>     <h1>console api</h1><br> </div><br> <script type="text/javascript"><br> var info = document.getElementById('console');<br> console.dirxml(info);<br> </script> Determine whether an expression or variable is true<script type="text/javascript"><br> var code = 200;<br> console.assert(code);<br> console.assert(code == 200);<br> console.assert(code == 500);<br> </script>Track function call traces<script type="text/javascript"><br> Function add(a,b) {<br> console.trace();<br>           return a + b;<br> }<br> <br> ​​add(1,2);<br> Add(2,3);<br> Add(3,4);<br> </script>Timing function<script type="text/javascript"><br> Console.time("Console timer") ;<br> console.log('Start');<br> for(var i=0;i<1000;i++) {<br> for(var j=0;j<1000;j++){<br>         }<br> }<br> console.log('End');<br> Console.timeEnd("Console timer");<br> </script> Analyze performance<script type="text/javascript"><br> Function getNews() {<br> ​​​​​_getAjax_1();<br> ​​​​​_getAjax_3();<br> }<br> <br> Function _getAjax_1 () {<br> for(var i=0;i<10;i++){<br> ​​​​​​​_getAjax_2();<br>         }<br> }<br> <br> Function _getAjax_2 () {<br> for(var i=0;i<100;i++){<br> ​​​​​​​_getAjax_3()<br>         }<br> }<br> <br> Function _getAjax_3 () {<br> for(var i=0;i<1000;i++){<br>         }<br> }<br> Console.profile('Performance Analyzer');<br> GetNews();<br> console.profileEnd();<br> </script> Warm reminder: Try using it and let yourself fall in love with the console!

Uploading pictures always fails. For renderings, you can view the source link.

Thanks ~

Source: http://mp.weixin.qq.com/s?__biz=MjM5NDM4MDIwNw==&mid=2448834664&idx=1&sn=7c4acdacc74ed1db81703be60e5537b1#rd

For more [dry information sharing], please follow my personal subscription account.

Console Api makes JS debugging simpler and more efficient

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template