Last active
December 14, 2015 22:28
-
-
Save johndkane/5158296 to your computer and use it in GitHub Desktop.
JavaScript console Polyfill / special case pattern. Basically prevents cross-browser console hell by implementing missing console and empty methods so no JS errors will occur.
I found this useful and decided to post a gist. There are many versions of it in the wild; this is only one.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Run this script before any others. | |
// Polyfill: provides a missing console and empty implementations for its missing methods. | |
(function(disable) { | |
if (!window.console) window.console = { }; | |
var methods = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"]; | |
for (var i = 0; i < methods.length; i++) { | |
if (disable || !console[methods[i]]) { | |
console[methods[i]] = function () { }; | |
} | |
} | |
console.log('console not an issue'); // << remove this line after verification of no error | |
})(false); //'disable' param: false to fill in only missing methods, true to replace *all* console methods with empty implementations |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment