My script sends text to the console output from several places in Javascript (see examples), how do I bind an event handler function to the log function itself so that a function is executed each time the event is triggered?
try {
//some code
} catch(e) {
console.log("error: "+e)
}
function x(n) {
//some code
console.log(str)
}
I would override console.log (but store it in a different variable, in case we want to use it) like so:
var nativeLog = console.log.bind(console) //store native function
console.log = function(text){ //override
nativeLog("<<<" + text)
}
Abbreviating console.log in JavaScript
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With