离开“console.log()”是不好的主意调用您的产品JavaScript代码? [英] Is it a bad idea to leave "console.log()" calls in your producton JavaScript code?
问题描述
我在我的JavaScript中有一堆 console.log()
调用。
我应该评论他们在我部署到生产之前呢?
我想把它们留在那里,所以我不必再去麻烦了,我需要做更多的调试。这是一个坏主意吗?
这将导致Javascript错误,终止执行包含错误的Javascript块。 / p>
但是,当Firebug不活动时,您可以定义一个无操作的虚拟函数:
if(typeof console ===undefined){
console = {log:function(){}};
}
如果您使用除 log
,您也需要存放这些。
I have a bunch of console.log()
calls in my JavaScript.
Should I comment them out before I deploy to production?
I'd like to just leave them there, so I don't have to go to the trouble of removing the comments later on if I need to do any more debugging. Is this a bad idea?
It will cause Javascript errors, terminating the execution of the block of Javascript containing the error.
You could, however, define a dummy function that's a no-op when Firebug is not active:
if(typeof console === "undefined") {
console = { log: function() { } };
}
If you use any methods other than log
, you would need to stub out those as well.
这篇关于离开“console.log()”是不好的主意调用您的产品JavaScript代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!