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

后端 未结 11 2007
醉话见心
醉话见心 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:21

    It will cause Javascript errors, terminating the execution of the block of Javascript containing the error.

    You could, however, define a dummy function that's a no-op when Firebug is not active:

    if(typeof console === "undefined") {
        console = { log: function() { } };
    }
    

    If you use any methods other than log, you would need to stub out those as well.

提交回复
热议问题