mirror of
https://github.com/h5bp/html5-boilerplate.git
synced 2026-01-11 23:58:21 -05:00
Improve console method stubbing
Avoid browsers with `console` and `console.log` throwing errors for some of the other methods that they did not support. Fix gh-1206 Close gh-1218
This commit is contained in:
committed by
Nicolas Gallagher
parent
e1b163041e
commit
578f377849
@@ -1,14 +1,19 @@
|
||||
// Avoid `console` errors in browsers that lack a console.
|
||||
if (!(window.console && console.log)) {
|
||||
(function() {
|
||||
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 = {};
|
||||
while (length--) {
|
||||
console[methods[length]] = noop;
|
||||
}
|
||||
}());
|
||||
}
|
||||
(function() {
|
||||
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 || {};
|
||||
|
||||
while (length--) {
|
||||
// Only stub undefined methods.
|
||||
console[methods[length]] = console[methods[length]] || noop;
|
||||
}
|
||||
}());
|
||||
|
||||
// Place any jQuery/helper plugins in here.
|
||||
|
||||
Reference in New Issue
Block a user