This post was published on Monday 25th of April 2005.
alertOverwriting the standard JavaScript alert() function with your own can provide you with a much more useful debugging tool.
For instance, I always seem to stick my debugging alerts inside endless (or at least frustratingly long) loops, without a proper way to cancel them. These simple lines of code eased my pain:
var _bMyAlert = true;
function MyAlert( sAlert ) {
if(_bMyAlert) {
_bMyAlert = confirm(sAlert);
}
}
window.alert = MyAlert;
Of course this is just the beginning, the possibilities are endless. You could for instance extend it to allow for an arbitrary amount of arguments and alert each on its own line:
var _bMyAlert = true;
function MyAlert( ) {
if(_bMyAlert) {
var sAlert = '';
for(var i=0; i<arguments.length; i++) {
sAlert += arguments[i] + '\n';
}
_bMyAlert = confirm(sAlert);
}
}
window.alert = MyAlert;
Have something to say about this post? Share your thoughts!
This post was published on Monday 25th of April 2005. The previous entry was "Coincidence? I think not!". The next entry is "Backbase launches new site".