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:
Devin Rhode
2012-09-20 10:52:17 -07:00
committed by Nicolas Gallagher
parent e1b163041e
commit 578f377849

View File

@@ -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.