Avoiding Polluting The Global Namespace With Javascript Dependencies
I'm building a javascript library and would like to bake in various dependencies (e.g, jQuery, Google Closure, etc) without polluting the global namespace. This is particularly im
Solution 1:
I believe you would need to modify the library source code to be able to do this, replacing their code:
window.jQuery = function(){ ... }
with:
myNamespace.jQuery = function() { ... }
Any any reference to the global jQuery object (and alias) would have to be namespaced, too. Similar measures would have to be taken for each JS library.
In my opinion, this is too much trouble for what it's worth. Taking up a single global variable for each js library is acceptable.
Post a Comment for "Avoiding Polluting The Global Namespace With Javascript Dependencies"