7 November 2010 2 comments JavaScript
This blog post is 12 years old! Most likely, its content is outdated. Especially if it's technical.
A classic blunder in Javascript client side apps is heavy use of the incredibly useful Firebug feature that is console.log()
and then forgetting to remove any such debugging and thus causing Javascript errors for people without Firebug. To remedy this use this little nifty function:
function log() {
if (window.console && window.console.log)
for (var i = 0, l = arguments.length; i < l; i++)
console.log(arguments[i]);
}
That way you can do plenty of debugging and if you accidentally leave a logging line in your code it won't break anything even if they don't have Firebug installed/enabled. Also you can easily "annotate" your debugging by writing two things in one line. Like this:
function foo(bar) {
log("bar is:", bar);
return bar * 2;
}
- Previous:
- In Django, how much faster is it to aggregate? 27 October 2010
- Next:
- Worst Flash site of the year 2010 8 November 2010
- Related by category:
- How to "onchange" in ReactJS 21 October 2015 JavaScript
- To then() or to success() in AngularJS 27 November 2014 JavaScript
- How to throttle AND debounce an autocomplete input in React 1 March 2018 JavaScript
- How to create-react-app with Docker 17 November 2017 JavaScript
- Display current React version 7 January 2018 JavaScript
- Related by keyword:
- Why I gave up on JQuery UI's autocomplete 20 October 2010
- What makes my website slow? DNS 23 October 2009
- Shout-out to eventlog 30 October 2014
- ReCSS a tool to reload the CSS without reloading the whole page 31 January 2006
- Messed up columns in Django Admin 16 October 2009
console.log can take multiple arguments. so it's possible to just apply all arguments of the custom log function to it:
console.log.apply(console, arguments);
Really?! That's cool. I'm going to try that.