js override console.log if not defined

后端 未结 7 795
庸人自扰
庸人自扰 2020-12-05 04:41

Which solution do you recommend, the second is simpler ( less code ), but there are drawbacks on using it ?

First: (Set a global debug flag)

7条回答
  •  天命终不由人
    2020-12-05 05:29

    EDIT: Andy's answer is way more elegant than the quick hack I've posted below.

    I generally use this approach...

    // prevent console errors on browsers without firebug
    if (!window.console) {
        window.console = {};
        window.console.log = function(){};
    }
    

提交回复
热议问题