-
Notifications
You must be signed in to change notification settings - Fork 23
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
Best practices on use of console #16
Comments
Hi Paul,
It is dying but not dead (unfortunately). And there are still developers who develop for it (that's my case for example). So when necessary, it can be useful to create a "empty" console object and populate it with no-operation methods when necessary. Basically: // Creates a console object when the browser does not provide the Console API
// and populates the console object with an empty function when the API is not complete.
(function() {
var methods = ["log", "info", "debug", "profile"/*, ... */];
if (!window.console)
window.console = {};
var noop = function(){ };
for (var i = 0; i < methods.length; i++) {
var method = methods[i];
if (!console[method])
console[method] = noop;
}
})();
Sure! Florent |
Important to note also that the follow evaluates to "undefined" === typeof console Once the console has been opened (attached), the condition will evaluate to false. The condition is false in IE10+ whether the developer tools (primarily the console) have been opened or not. |
+1 @jonathansampson - it's actually noted as noted in goals already https://github.com/DeveloperToolsWG/console-object#goals - but I think it should go in a best-practices piece along with the above and a link to a polyfill or at least 'non-breaking api' like above. Best version of @fflorent's example in full seems to be https://github.com/h5bp/html5-boilerplate/blob/master/js/plugins.js |
I'm thinking we could add this for users.
The text was updated successfully, but these errors were encountered: