js setzt console.log außer Kraft, wenn nicht definiert
Welche Lösung empfehlen Sie, die zweite ist einfacher (weniger Code), aber es gibt Nachteile bei der Verwendung?
Zuerst (Ein globales Debug-Flag setzen)
// the first line of code
var debug = true;
try {
console.log
} catch(e) {
if(e) {
debug=false;
}
};
// Then later in the code
if(debug) {
console.log(something);
}
Zweite console.log überschreiben
try {
console.log
} catch(e) {
if (e) {
console.log = function() {}
}
};
// And all you need to do in the code is
console.log(something);