js屏蔽掉调试时写的console.log

xiaoxiao2021-02-28  96

这属于代码级别的修改,重写console.log(),下面贴代码,有详细的注释:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 <!DOCTYPE html> <html>      <head>          <meta charset= "{CHARSET}" >          <title></title>          <script>              var  Debugger =  function  () {               };              //开关,是否显示输出              Debugger. switch  =  true ;              Debugger.log =  function  (message){                  try {                      if (Debugger. switch ){                          console.log(message);                      }                                    } catch (exception){                      return  'Error:the function  log is not exist.' ;                  }              }                                          var  name =  '音乐586' ;                            //会在控制台输出'音乐586'              Debugger.log(name);                            //如果你不想有输出,把开关关了即可              Debugger. switch  =  false ;                            Debugger.log(name); //控制台不再输出name          </script>      </head>      <body>      </body> </html> 还有一种方法是直接将console.log的功能去掉,js开头写console.log=function(){};算是一个小技巧。。
转载请注明原文地址: https://www.6miu.com/read-71838.html

最新回复(0)