so ive 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 cannot understand why this makes me think that something is wrong here.

Hello world is generated by log.call(console, a)
as expected
submitmsg()
is my custom function
this works exactly the way I want, as I said, although I'm a little worried that it also returns “undefined” for reasons I don’t understand.
Note. The following code was published by OP as an answer to a question. Comments on the answer have been moved to comments on this issue.
So the correct code should be as follows:
var log = Function.prototype.bind.call(console.log, console); console.log = function (a) { return log.call(console, a); submitmsg("Log", a) };
source share