Freitag, 12. Februar 2010

Console.log() vs. Alert()

Why do people still use alert()? It's annoying, can only display strings properly, [object Object] is useless. It stops the execution of the script and it needs you to click ok. Why not use console.log instead? Console.log is supported across all modern Browsers, including IE8!

"But my script will break in IE6 if I use console.log"

Dude, it takes 5 lines of JavaScript to fix that problem and you don't want the user to be annoyed by cryptic debugging Information, do you?

if( !window.console){
window.console = {
log: window.alert
};
}

This is not even difficult pro-technique js. Personally I prefer:

var cl = window.console ? console.log : function(){};


Every time you use alert(), God kills a kitten!


mfG Kambfhase

Keine Kommentare:

Kommentar veröffentlichen