防止IE不支持console.log报错

方案一:

var console = console || {
        log : function() {
            return;
        }
    };//兼容IE,当IE不支持console.log时,自定义一个包含log方法的对象给他

方案二:HTML5 Boilerplate 也提供了一个处理所有的 Console call 的 fallback

// Avoid `console` errors in browsers that lack a console.
(function() {
    var method;
    var noop = function () {};
    var methods = [
        'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error',
        'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log',
        'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd',
        'timeStamp', 'trace', 'warn'
    ];
    var length = methods.length;
    var console = (window.console = window.console || {});
    while (length--) {
        method = methods[length];
        // Only stub undefined methods.
        if (!console[method]) {   //对于不支持的方法用noop函数代替
            console[method] = noop;
        }
    }
}());
// Place any jQuery/helper plugins in here.

方案三:自定义封装个方法调用

    function log(msg){
        if (window["console"]){
            console.log(msg);
        }
    }
原文地址:https://www.cnblogs.com/liaojie970/p/5028475.html