How to quickly and conveniently disable all console.log statements in my code?

后端 未结 28 2199
深忆病人
深忆病人 2020-11-22 16:48

Is there any way to turn off all console.log statements in my JavaScript code, for testing purposes?

28条回答
  •  清酒与你
    2020-11-22 17:31

    I realize this is an old post but it still pops up at the top of Google results, so here is a more elegant non-jQuery solution that works in the latest Chrome, FF, and IE.

    (function (original) {
        console.enableLogging = function () {
            console.log = original;
        };
        console.disableLogging = function () {
            console.log = function () {};
        };
    })(console.log);
    

提交回复
热议问题