4 ms·
I have run into problems in the past caused by forgetting to remove console.log() lines from my scripts. If the console wasn't open, then the scripts didn't wor
by hundredwatt 16y ago
I have run into problems in the past caused by forgetting to remove console.log() lines from my scripts. If the console wasn't open, then the scripts didn't work.
This isn't a huge problem or reason not to use Firebug (which I would be totally lost without), just something to be wary of.
- notauser 16y agoYou can solve(?) this by creating a dummy console.log object when one isn't already present, then throwing away all of the output.
- maxanger 16y agoif (window.console) console.log(...);
- jackowayed 16y agoThat really should be built in to console.log.
- geocar 16y agoif(!console)console={log:function(){}}; You're welcome.
- marcuswestin 16y agoThis will throw if console is not defined. Try if (!window.console) Or if (typeof console == 'undefined') Or if !('console' in window)) N
- geocar 16y agoDoesn't here. What are you using?
- toni 16y agoMy solution to this issue was to write a console2.log helper function and call that instead of the original console.log: var console2 = { log: function(msg){ if(typeof console != 'undefined'){ console.log(msg); } } }
- devpopol 16y agoif(!window.console){window.console = {};} if(!(toString(window.console.log) === '[object Function]')) {window.console.log = function(){};} there, fixed..
- jmtulloss 16y agoThis won't work in node. That's not a huge deal, but it's pretty simple to come up with a cleaner solution that works in all environments.