Last active
January 2, 2016 17:09
-
-
Save Jpunt/8334615 to your computer and use it in GitHub Desktop.
Fallback to use things like console.log() but not have it kill old browsers.
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
// This is not some kind of polyfill! It's just to prevent old browsers from failing horribly | |
var fallback = function() {}; | |
var methods = ['assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log', 'profile', 'profileEnd', 'time', 'timeEnd', 'timeStamp', 'trace', 'warn', 'table']; | |
if(typeof console === 'undefined') { | |
var console = {}; | |
} | |
for(var i in methods) { | |
if(typeof console[methods[i]] === 'undefined') { | |
console[methods[i]] = fallback; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment