Monday, June 9, 2008

debug

  • FF: Firebug : https://addons.mozilla.org/en-US/firefox/addon/1843
  • IE: DebugBar : http://www.debugbar.com/
  • SF: Developer: http://developer.apple.com/internet/safari/faq.html#anchor14

Debug in production?! .. when you have to .. you can target a strange userAgent string .. such as "Quality Assurance Browser" .. that you set yourself with some tool that allows you to set your userAgent.

Tuesday, June 3, 2008

YUI Compressor wishlist

Ok, so my list is currently composed of only one item: Flag for always remove. YUI Compressor already has a flag to *never* remove /** comments **/ that probably contain copyright information. I'd like it if YUI Compressor had a flag to *always* remove a block of code. Use case: remove debug statements. Perhaps it could be implemented as comments that demarcate the debug block, such as:



/** debug **/
console.dir( myObj );
/**/




and a corresponding YUI Compressor command-line argument "-rmdebug"




$ java -jar yuicompressor-2.5.2.jar -rmdebug script.js -o script-min.js





Update: Ok, so.. after I posted this, I searched the yuicompressor feature request list, and natch, somebody requested this - at least the debug-one-liner version: treat as debug any line that is prefixed with ";;". YUI Compressor Feature Request: remove debug code.




;; console.dir( myObj ); //double-semicolon prefix indicates this line is for debugging

Monday, June 2, 2008

Working with JSON

Often, on a callback that receives json, you may be tempted to do something such as:

if (data.image.length) {
    // Group of images
    for (var i = 0; i < data.image.length; i++) {
        debug("Image " + data.image[i].imageUrl + ": " + data.image[i].statusText);
    }
}
else {
    // Just a single image
    debug("Image " + data.image.imageUrl + ": " + data.image.statusText);
}

but it can be expressed more succinctly as:


if (!data.image.length) data.image = [data.image];
// Group of images
for (var i = 0; i < data.image.length; i++) {
    debug("Image " + data.image[i].imageUrl + ": " + data.image[i].statusText);
}