1
如果通过高级优化运行以下代码,我仍然可以在代码中看到调试语句。经过高级模式编译使用Google Closure Compiler去除调试代码
(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);
})();
如何才能摆脱调试信息与先进模式
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;
}
输出?
如果调试变量被定义为全局的,和日志记录语句被封入等
如果(DEBUG){ 日志( '调试消息'); }
那么它会工作,但有没有办法让它工作,如果我们不希望它作为一个全局变量,而是通过参数传递给各个模块/函数。
看起来这是接近我们会得到回答的问题 – sbr 2015-04-01 22:41:25