-
Notifications
You must be signed in to change notification settings - Fork 12.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
remove log() #1107
remove log() #1107
Conversation
The stubbed versions being the |
If we’re assuming jQuery anyway, how about something like this? // Avoid `console` errors in browsers that lack a console
if (!(window.console && console.log)) {
window.console = {};
$.each(['error', 'warn', 'info', 'debug', 'log'], function() {
window.console[this] = $.noop;
});
} It’s easy enough to do without using |
We avoided the Modernizr dependency for the GA snippet, so we should probably avoid a jQuery dependency here too. |
Yeah, our console noop is already pretty damn terse. |
I was just about to raise this same issue.. I tried to see if there's some sort of closure that can amend this.. but I couldn't figure out anything. |
I've found this little abstraction to be really helpful. I mean, I very rarely ever click the line number on my log statements. I'll click it on syntax errors sometimes, but not often. |
Anyone want to have a go at doing this? |
Here’s the obvious sans-jQuery adaptation of my earlier suggestion: // Avoid `console` errors in browsers that lack a console
if (!(window.console && console.log)) {
(function() {
var noop = function() {},
methods = ['error', 'warn', 'info', 'debug', 'log'],
index = -1,
length = methods.length;
console = window.console = {};
while (++index < length) {
console[methods[index]] = noop;
}
}());
} If this looks good I’ll commit it following the style guide (I’m using tabs here). Here’s an alternate version that looks prettier IMHO: // Avoid `console` errors in browsers that lack a console
(window.console && console.log) || (function() {
var noop = function() {},
methods = ['error', 'warn', 'info', 'debug', 'log'],
index = -1,
length = methods.length,
console = window.console = {};
while (++index < length) {
console[methods[index]] = noop;
}
}()); |
Thanks. Pull request! |
A bit smaller: if (!(window.console && console.log)) {
(function() {
var noop = function() {},
methods = ['error', 'warn', 'info', 'debug', 'log'],
i = methods.length,
console = window.console = {};
while ( i-- ) {
console[methods[i]] = noop;
}
}());
} |
P.S. I vote for multiple |
m2 |
Pull request attached. I’ve added all the console API methods that were there in the old version, plus added some that were missing (including Note: multiple commits, so please squash them together before merging. |
var length = methods.length; | ||
var console = window.console = {}; | ||
while (length--) { | ||
console[methods[index]] = noop; |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
Thanks! Please could you squash these commits. |
Remove the previous `log()` wrapper method as it changed the reported line position in logs. Instead, avoid `console` errors in browsers without `console` by setting its methods to empty functions. Ref. #1107.
Merged into master in 5370479 |
Any thoughts on re-adding |
I actually just figured out how you can get the click through back, basically if you display the string "url:lineNo" you can click it and have the same effect as the devtools link. So I'll be doing something where I temporarily abuse onerror to get the file url and line number, and then re-console log with the original args and the file url:lineNumber The project I'm working on is close to a 1.0 beta or 0.6, and the sub-component that will do this is here devinrhode2/historicalConsole.js#3 |
even shorter))
|
Got a great comment on my log() post that pointed out the obvious fact that using the wrapper changes the reported line position of your logs.
This makes clicking through to the Scripts panel far less useful, as well as losing context that a glance at the logged lines can give you.
I think it's best to remove
log()
and recommend full use ofconsole.log()
with the stubbed versions for IE7.(while we're at it, less add
timeStamp
to the console stub script.)