software-mariodiana
8/11/2014 - 1:18 PM

Snippet to keep Internet Explorer from choking on console.log statements, when the Developer tab is closed.

Snippet to keep Internet Explorer from choking on console.log statements, when the Developer tab is closed.

// Handle console logging in IE. - http://stackoverflow.com/a/16916941/155167
(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]) {
            console[method] = noop;
        }
    }
}());