We using google closure as the build tool for a medium size javascript project. To make it easier to protect the code we turned on the ADVANCED_OPTIMIZATION option. The result were lots of dangerous use of the global this object
warnings.
There are several workarounds discussed like here but I dont find them really satisfying. The first thing annoying me is to put everything in the global namespace. Isnt this a really bad architecture style from the old days of functional programming? This means changes throughout the whole project whenever someting global changes...
The other solution would be to use the @constructor annotation throughout the code. This would change nearly every object method into a (documented) constructor (we have more than thousand ...). Before starting to annotate everything: is it safe to use the annotation method (e.g. is the code working after optimization)? Maybe the code is not obfuscated within the annotated methods?
Is there really no better alternative as these two above?