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

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

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

28条回答
  •  Happy的楠姐
    2020-11-22 17:37

    After I searched for this issue aswell and tried it within my cordova app, I just want to warn every developer for windows phone to not overwrite

        console.log
    

    because the app will crash on startup.

    It won't crash if you're developing local if you're lucky, but submitting in store it will result in crashing the app.

    Just overwrite

        window.console.log 
    

    if you need to.

    This works in my app:

       try {
            if (typeof(window.console) != "undefined") {
                window.console = {};
                window.console.log = function () {
                };
                window.console.info = function () {
                };
                window.console.warn = function () {
                };
                window.console.error = function () {
                };
            }
    
            if (typeof(alert) !== "undefined") {
                alert = function ()
                {
    
                }
            }
    
        } catch (ex) {
    
        }
    

提交回复
热议问题