Ensures there will be no 'console is undefined' errors

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

 //Ensures there will be no 'console is undefined' errors
window.console = window.console || (function(){
var c = {};
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){};
return c;
})();
上一篇:JS实现 点击button(copy) 复制对应的网址——类似于复制推广链接


下一篇:Android中两种设置全屏或者无标题的方法