How to safely wrap `console.log`?

后端 未结 10 506
日久生厌
日久生厌 2021-01-31 14:13

Suppose I want to include some calls to console.log for some legitimate production reason, say for something like a unit test harness. Obviously I would not want th

10条回答
  •  既然无缘
    2021-01-31 15:18

    Sorry, there was a bug in my post. Don't know how I missed it.

    The PROPER way to create a global console object, if it does not exist:

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

提交回复
热议问题