Javascript best practice: handling Firebug-specific code

前端 未结 9 867
春和景丽
春和景丽 2021-02-03 10:31

Firebug is certainly a wonderful tool for javascript debugging; I use console.log() extensively.

I wanted to know if I can leave the Firebug-specific code in production.

9条回答
  •  轮回少年
    2021-02-03 10:43

    been bitten by this before. Ideally all the console.log statements need to be removed before production, but this is error prone and developers invariably forget or only test in FF + Firebug.

    A possible solution is to create a dummy console object if one isn't already defined.

    if( typeof window.console == 'undefined'){
        window.console = {
            log:function(){}
        };
    }
    

    One word of caution: It used to be the case for Safari on 10.4 that any call to console.log would throw a security exception as the console object is a reserved object used in the Mac OS Dashboard widgets. Not sure this is the case anymore, will check tonight.

提交回复
热议问题