【发布时间】:2015-03-30 18:47:04
【问题描述】:
如果我通过高级优化运行以下代码,我仍然可以看到代码中的调试语句。
var log = console.info.bind(console);
(function() {
/** @const */
var DEBUG = false;
log('Brady', createRank({
max: 100,
debug: DEBUG
}));
})();
function createRank(options) {
if (options.debug) {
log('This should be in debug mode only');
}
if(typeof alert == 'function'){
alert(options);
}
return (Math.random() * options.max) | 0;
}
高级模式编译后的输出
(function() {
var a = console.info.bind(console),
b = {
max: 100,
debug: !1
};
b.debug && a("This should be in debug mode only");
"function" == typeof alert && alert(b);
a("Brady", Math.random() * b.max | 0);
})();
我们怎样才能摆脱高级模式的调试信息?
如果 DEBUG 变量被定义为全局变量,并且日志语句被括起来
如果(调试){ 日志('调试消息'); }
那么它会起作用,但是如果我们不希望它作为全局变量,而是通过参数将值传递给各个模块/函数,有没有办法让它起作用。
【问题讨论】:
标签: javascript gruntjs gulp google-closure-compiler google-closure