I am trying to get google closure compiler to remove some logging function calls from my javascript without any success. Here is my test code that reproduces what I am seeing
/** @define {boolean} */
var ENABLE_LOGGING = true;
(function() {
function obj(name) {
this.name = name;
}
obj.prototype = {
log: ENABLE_LOGGING ?
function(msg) { console.log(this.name + ': ' + msg); } :
function(msg) {}
};
var A = new obj('bob');
var B = new obj('tom');
A.log('I am an object!');
B.log('I am another object!');
})();
When I compile this with java -jar ./compiler.jar --define ENABLE_LOGGING=false --compilation_level ADVANCED_OPTIMIZATIONS --js test.js
, it produces this output (pretty printed for clarity):
(function() {
function a(a) {
this.name = a;
}
a.prototype = {log:function() {
}};
var b = new a("tom");
(new a("bob")).log("I am an object!");
b.log("I am another object!");
})();
What would be the correct way to get closure compiler to leave out the logging code? Here it is leaving in a call to a function that does nothing.