Thursday 16 November 2017

Can I extend the console object (for rerouting the logging) in javascript?

itemprop="text">

Is it possible to extend the console
object?



I tried something
like:




Console.prototype.log
= function(msg){
Console.prototype.log.call(msg);

alert(msg);
}


But
this didn't work.
I want to add additional logging to the console object via a
framework like rel="noreferrer">log4javascript and still use the standard console object
(in cases where log4javascript is not available) in my
code.




Thanks in
advance!



Answer




Try
following:



(function()
{
var exLog = console.log;
console.log = function(msg)
{
exLog.apply(this, arguments);
alert(msg);

}

})()


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...