Donnerstag, 1. Dezember 2011

console.log & debug flag?

Instead of checking the DEBUG flag everytime you need a debug info, like this:

    if (DEBUG) {
        console.log("my debug output");
    }

you can just check the DEBUG flag once and disable the console.log function, like this:

    if (DEBUG === false) {
        console = {
            log: function() {}
        };
    }

This enables you to simply call:

    console.log("my debug output")

in your application. If DEBUG is true, you'll get your output. If DEBUG is false, console.log() will be called but is an empty function and thus will produce no output / error.

Keine Kommentare:

Kommentar veröffentlichen