如何修补console.error或info,但为Firebug留下完整的跳转网址?

时间:2012-11-16 18:05:53

标签: javascript firebug

我看到很多帖子如何替换其他人的JS控制台功能,但没有人为Firebug保留完整的。

当我替换其中任何一个时,它会调用我的自定义函数,但它会从新函数所在的相同位置报告该消息。

这里的目标是接收任何这些控制台消息并将其显示在其他地方,同时我仍然可以在Firebug控制台中跳转到被调用者。

这有可能吗?

更新: 例如(PSEUDO):

//keep the old one
var oriFn=console.error;

console.error=function(){
   someOtherFunc(arguments);//send to server for instance
   oriFn(arguments);
} 

现在在其他地方,我想像往常一样调用console.error('bla');在Firebug控制台中,它会打印我的消息,但会显示上面替换代码的链接。我希望在Firebug控制台中链接到被调用者的父函数,就是这样。

1 个答案:

答案 0 :(得分:0)

使用函数指针。鉴于foo.js:

function foo()
 {
 console.error = console.log; //Reassign console.error
 location.hash = document.title; //Do something
 console.error("Not the mama");  //Outputs line foo.js:5
 }

<强>参考