Yes, Closure Compiler can do so in advanced compilation mode, however annotations are required to prevent automatic removal of the prototype
property. For example, this:
var CONST1 = 5;
var CONST2 = 10;
function Test() {
abc = 123;
this.xyz = 234;
}
Test.prototype = {
do_it: function(argX, argY) {
return (argX + abc) / CONST1 + (argY + this.xyz) / CONST2;
}
};
is annotated as this:
var CONST1 = 5;
var CONST2 = 10;
/** @constructor */
function Test() {
abc = 123;
this.xyz = 234;
}
/** @expose */
Test.prototype = {
do_it: function(argX, argY) {
return (argX + abc) / CONST1 + (argY + this.xyz) / CONST2;
}
};
window["Test"] = Test;
then when it is run, converted to this:
function a() {
abc = 123;
this.a = 234;
}
a.prototype = {b:function(b, c) {
return(b + abc) / 5 + (c + this.a) / 10;
}};
window.Test = a;