Last Updated: February 25, 2016
·
215
· kotrotsos

Overriding the alert method.

I was kinda surprised this worked- but, now I see it work, I can't figure why it wouldn't work.

function alert() {
        for (var i=0, total = 0, len=arguments.length;
                i<len; i++) {
                    console.log( arguments[i] );
        }
}

alert( 'well, would be surprised if this works','as is','Consider me surprised!' );

I know it never is a good idea to extend (or overwrite like this) default methods. So just consider this a show-and-tell type of thing.

A shorter version would of course look like:

function alert( msg ) {
        console.log( msg );
}