我可以在 javascript 中扩展控制台对象(用于重新路由日志记录)吗? [英] Can I extend the console object (for rerouting the logging) in javascript?
本文介绍了我可以在 javascript 中扩展控制台对象(用于重新路由日志记录)吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以扩展控制台对象?
Is it possible to extend the console object?
我尝试了类似的东西:
Console.prototype.log = function(msg){
Console.prototype.log.call(msg);
alert(msg);
}
但这没有用.我想通过像 log4javascript 这样的框架向控制台对象添加额外的日志记录,并且仍然使用标准的控制台对象(如果log4javascript 不可用)在我的代码中.
But this didn't work. I want to add additional logging to the console object via a framework like log4javascript and still use the standard console object (in cases where log4javascript is not available) in my code.
提前致谢!
推荐答案
尝试以下操作:
(function() {
var exLog = console.log;
console.log = function(msg) {
exLog.apply(this, arguments);
alert(msg);
}
})()
这篇关于我可以在 javascript 中扩展控制台对象(用于重新路由日志记录)吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文