Ensures there will be no 'console is undefined' errors

很早之前项目中遇到过这种bug, 当时没有多留意,只是暂时把笔记留了下来,今天整理笔记的时候,看到了,故先整理在此,具体用法下次遇到再好好理解理解。如果有筒子遇到过,麻烦留言说一下,先谢谢啦。

1 //Ensures there will be no 'console is undefined' errors
2 window.console = window.console || (function(){
3     var c = {};
4     c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile = c.clear = c.exception = c.trace = c.assert = function(s){};
5     return c;
6 })();
原文地址:https://www.cnblogs.com/xiayu25/p/6242503.html