Skip to content

Instantly share code, notes, and snippets.

@daviferreira
Created May 14, 2013 14:40

Revisions

  1. daviferreira renamed this gist May 14, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. daviferreira created this gist May 14, 2013.
    21 changes: 21 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    /**
    * Protect window.console method calls, e.g. console is not defined on IE
    * unless dev tools are open, and IE doesn't define console.debug
    */
    (function () {
    if (!window.console) {
    window.console = {};
    }
    // union of Chrome, FF, IE, and Safari console methods
    var functionCall = function () {},
    i,
    m = ['log', 'info', 'warn', 'error', 'debug', 'trace', 'dir', 'group',
    'groupCollapsed', 'groupEnd', 'time', 'timeEnd', 'profile', 'profileEnd',
    'dirxml', 'assert', 'count', 'markTimeline', 'timeStamp', 'clear'];
    // define undefined methods as noops to prevent errors
    for (i = 0; i < m.length; i += 1) {
    if (!window.console[m[i]]) {
    window.console[m[i]] = functionCall;
    }
    }
    }());