4 ms·
Combining a response to a few comments here. > Based on your definition of "giant global variable" the $ in JQuery is also precisely that. jQuery’s `$` and `j
by minitech 10y ago
Combining a response to a few comments here.
> Based on your definition of "giant global variable" the $ in JQuery is also precisely that.
jQuery’s `$` and `jQuery` are giant global variables when you include jQuery as a <script> or by concatenation. When you load it as a module, it adds no globals, which is rather nice. Look at https://www.npmjs.com/package/jquery’s https://www.npmjs.com/package/jquery’s “Babel” section, which is also how you use it with TypeScript.
You also seem to be under the impression that polluting the global namespace is the only bad thing about globals. It’s one factor, but it’s also just generally an indicator of bad design. Organizing global mutable state into singletons and namespaces doesn’t help with this. You’re also crowing about TypeScript but throwing away many of its benefits by not using modules or typings for the libraries you depend on.
> You may not even know this, but packaging an app into a single downloadable JS file (modules not even necessary) is actually the modern approach. It lends itself to better compression+minification.
(ES6) modules actually quite necessary if you want your minifier/bundler to be able to remove unused code reliably. Closure Compiler can only do so much.