-
Notifications
You must be signed in to change notification settings - Fork 12.3k
Commit
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
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 || {}; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
bgrins
Member
|
||
|
||
while (length--) { | ||
// Only stub undefined methods. | ||
console[methods[length]] = console[methods[length]] || noop; | ||
This comment has been minimized.
Sorry, something went wrong.
drublic
Member
|
||
} | ||
}()); | ||
|
||
// Place any jQuery/helper plugins in here. |
1 comment
on commit 578f377
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to patch
The reason I was using
var console = window.console = {};
is to make sure a globalconsole
object would be available, even in browsers that lack one.Unless I’m missing something, the current code doesn’t expose
console
to the global scope at all./me reads gh-1218…