So I've hijacked the console function:
var log = Function.prototype.bind.call(console.log, console);
console.log = function (a) {
log.call(console, a);
submitmsg("Log", a);
};
This has the desired effect. However, it also returns "undefined" as an unexpected bonus.
I can't figure out why which leads me to think there is something slightly wrong here.
Hello world is generated by log.call(console, a)
as expected
submitmsg()
is my custom function
This is working exactly how I want. As I said though, I'm slightly concerned that it is also returning "undefined" for reasons I do not understand.
Note: The following code was posted by the OP as an answer to the question. The comments on the answer have been moved to the comments on the question.
So should the correct code be the following?
var log = Function.prototype.bind.call(console.log, console);
console.log = function (a) {
return log.call(console, a);
submitmsg("Log", a)
};