Skip to content

Instantly share code, notes, and snippets.

@Moinax
Forked from peteboere/README.md
Created April 17, 2014 12:33
Show Gist options
  • Save Moinax/10979788 to your computer and use it in GitHub Desktop.
Save Moinax/10979788 to your computer and use it in GitHub Desktop.

Revisions

  1. @peteboere peteboere created this gist Nov 26, 2012.
    6 changes: 6 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    Avoid `console` errors in browsers that lack a console.

    Excerpted from HTML5 boilerplate:

    * [HTML5 Boilerplate](https://github.com/h5bp/html5-boilerplate)
    * [Original commit](https://github.com/h5bp/html5-boilerplate/blob/750bf0e093a0a80ad785e38f23db38ad077a2d80/js/plugins.js)
    3 changes: 3 additions & 0 deletions component.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    {
    "name": "native-console"
    }
    22 changes: 22 additions & 0 deletions native-console.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    // Avoid `console` errors in browsers that lack a console.
    (function() {
    var method;
    var noop = function noop() {};
    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;
    }
    }
    }());