所以我劫持了控制台功能
var log = Function.prototype.bind.call(console.log, console);
console.log = function (a) {
log.call(console, a);
submitmsg("Log", a);
};
Run Code Online (Sandbox Code Playgroud)
这有所期望的效果,但它也会返回"未定义"作为意外奖励
我无法弄清楚为什么导致我认为这里有一点点错误

Hello world log.call(console, a)按预期生成
submitmsg() 是我的自定义功能
这正是我想要的,正如我所说的虽然我稍微担心它也因为我不理解的原因而返回"未定义".
注意: OP发布了以下代码作为问题的答案.对答案的评论已移至对该问题的评论.
所以正确的代码应该如下?
var log = Function.prototype.bind.call(console.log, console);
console.log = function (a) {
return log.call(console, a);
submitmsg("Log", a)
};
Run Code Online (Sandbox Code Playgroud) javascript ×1