I've got a fairly elaborate class which uses the old-style way of creating classes. Rather than using the class keywords, classes are defined using the function keyword. To create public properties, you assign this.publicProperty. My code works quite well.
However, when I try to use the Closure Compiler (a JS minifier tool) in advanced mode, I get bazillions of errors, starting with one about 'dangerous' references to this. Here's a trivial example which illustrates my problem. I try to compress this trivial JS code:
var myclass = function(p1, p2) {
this.publicProperty = null;
};
The Compiled Code output is empty and there's a warning:
JSC_USED_GLOBAL_THIS: dangerous use of the global this object at line 2 character 2
this.publicProperty = null;
^
Why is this 'dangerous' ?
I've seen other posts here on SO which clearly show that my code seems OK. Why does the Closure minifier complain about this?
As a secondary question, I'd like to know if anyone can suggest an effective browser-based JS minifier that will compress your JS down to a single line of code. I've tried Uglifier and Closure and javascript-minifier am unable to get minified JS output that's just a single line of code.