覆盖console.log();用于生产 [英] Override console.log(); for production
问题描述
我有一个 sencha-touch 应用程序充满了 console.log() ;
用于调试目的。
我有 chirpy 完成我的所有构建时间的组合。它输出一个 app.debug.js
进行调试,以及 app.min.js
用于生产
现在,我可以查看我所有的代码文件,寻找 console.log();
并手动删除,当我'准备去生产,但是我想知道是否有办法重写方法。
基本上,每当 console.log( );
方法被调用,DO NOTHING。
这样,我可以把重写代码文件放在我的生产配置中,而不是在我的调试配置
这是可能吗?
文件的顶部:
var console = {};
console.log = function(){};
对于某些浏览器和细分,您可能需要将其应用于窗口对象。
window.console = console;
I'm fairly new to Javascript development so this might be a real newbie question.
I've got a sencha-touch application riddled with console.log();
for debugging purposes.
I've got chirpy doing all of my build time combining. It outputs a app.debug.js
for debugging as well as a app.min.js
for production
Now I could go through all of my code files looking for console.log();
and delete it manually when I'm ready to go to production, but I'm wondering if there's a way to override the method.
Basically, whenever the console.log();
method is called, DO NOTHING.
That way, I can put the override code file in my production config, and NOT in my debug config.
Is this possible?
Put this at the top of the file:
var console = {};
console.log = function(){};
For some browsers and minifiers, you may need to apply this onto the window object.
window.console = console;
这篇关于覆盖console.log();用于生产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!