覆盖 console.log();用于生产 [英] Override console.log(); for production
问题描述
我对 Javascript 开发还很陌生,所以这可能是一个真正的新手问题.
I'm fairly new to Javascript development so this might be a real newbie question.
我有一个 sencha-touch 应用程序充满了 console.log();
用于调试目的.
I've got a sencha-touch application riddled with console.log();
for debugging purposes.
我让 chirpy 做所有的事情我的构建时间结合.它输出一个 app.debug.js
用于调试,以及一个 app.min.js
用于生产
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
现在我可以浏览我的所有代码文件,寻找 console.log();
并在我准备投入生产时手动删除它,但我想知道是否有重写方法的方法.
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.
基本上,每当 console.log();
方法被调用时,什么都不做.
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.
这可能吗?
推荐答案
把这个放在文件的顶部:
Put this at the top of the file:
var console = {};
console.log = function(){};
对于某些浏览器和缩小器,您可能需要将其应用到 window 对象上.
For some browsers and minifiers, you may need to apply this onto the window object.
window.console = console;
这篇关于覆盖 console.log();用于生产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!