覆盖console.log();用于生产 [英] Override console.log(); for production

查看:231
本文介绍了覆盖console.log();用于生产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个 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 application riddled with console.log(); for debugging purposes.

I've got 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆