I am experimenting with the advanced mode of the Google Closure compiler and it seems that small simple functions are only built in when they are not wrapped in an anonymous shell. Looking for an explanation / solution or a hint of what I'm doing wrong.
This is my test:
function Test() { } Test.prototype.div = function (index) { return Math.floor(index / 32); }; Test.prototype['test'] = function (index) { return this.div(index); }; window['Test'] = Test;
which leads to this little script where the div
function is inlined :
function a() { } a.prototype.test = function(b) { return Math.floor(b / 32) }; window.Test = a;
Then the test is wrapped as follows:
(function () { // <-- added function Test() { } Test.prototype.div = function (index) { return Math.floor(index / 32); }; Test.prototype['test'] = function (index) { return this.div(index); }; window['Test'] = Test; }()); // <-- added
div
function not specified :
(function() { function a() { } a.prototype.a = function(a) { return Math.floor(a / 32) }; a.prototype.test = function(a) { return this.a(a) }; window.Test = a })();
Is there any side effect that I don't know about that prevents embedding here?
Update 1 . I use an online compiler with a ticked checkmark with advanced mode + nice print run.
Update 2 . Found that the command line parameter --output_wrapper
can be used as a workaround, --output_wrapper "(function() {%output%})();"
.
source share