Cleaning up the console #2

Merged
merged 1 commit into from Nov 29, 2011

Projects

None yet

3 participants

@brittohalloran
Contributor

Hey - good extension here Adam

Your released version pollutes the console log which gets in my way when I'm developing other stuff and looking at the console. I added a simple consoleLog() function where you can switch on and off dev mode easily and in one place.

There are console.log()'s in your other JS files also, but I didn't modify them because I'm not totally sure how they interact. I suspect you could combine a couple JS files and maybe namespace your js to avoid crashing with other sites (since your JS is running in every tab on every site). This is the way I like:

var adampash = function(){

    var tree = 4;
    var dog = 5;

    var play = function(){
        ...
    };

    $(function(){
        // this is the only section
        // that will run on page load
        play(tree);
    });

}(); // this '()' is key, it makes adampash a 'self-invoking' function (autorun)

Good stuff though in general. Just switched completely to Google Music.

Britt O'Halloran

@justinforce

+1. I'd really like to see the console.log calls removed. I have to disable Music Plus when I'm doing development, which is most of the time that I'm using my computer. :)

@justinforce

The suggested function actually diminishes the functionality of console.log which can accept multiple arguments. I often use comment.log(arg, otherArg, anotherArg);

A better approach might be

dbg = false; // set to true if we're debugging
function log() {
  if (dbg) console.log(arguments);
}

log('examining jQuery function and selection:', $, $('div')); // succinct syntax; only logs if dbg == true

You don't need to use the less clear var log = function() {} syntax or the var keyword for dbg since extension declarations won't pollute the namespace. If you can avoid that you should, since hoisting may not behave intuitively.

Great idea - using arguments is a better idea.

I didn't know that chrome extensions were sandboxed - and thanks for the hoisting link, learned some new stuff there. I like to do my namespaces like this, which helps me keep hoisting straight.

And thank you for the namespace link. :)

Owner

Thanks v. much for the suggestion. Can you submit a pull request?

(Also, I realize this is months late. I do really appreciate the suggestion, though!)

Owner

Oh nm, I'm an idiot. You have submitted a pull request. Merging!

@adampash adampash merged commit ef5f9cb into adampash:master Nov 29, 2011
@brittohalloran
Contributor

Awesome - thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment