Bad idea to leave “console.log()” calls in your production JavaScript code?

后端 未结 11 2027
醉话见心
醉话见心 2020-12-07 08:03

I have a bunch of console.log() calls in my JavaScript.

Should I comment them out before I deploy to production?

I\'d like to just leave them th

11条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-07 08:37

    As other have mentions it will thrown an error in most browsers. In Firefox 4 it won't throw an error, the message is logged in the web developer console (new in Firefox 4).

    One workaround to such mistakes that I really liked was de&&bug:

    var de = true;
    var bug = function() { console.log.apply(this, arguments); }
    
    // within code
    de&&bug(someObject);
    

提交回复
热议问题