Well, the second means that you also want functions and objects and everything in your modules to be in a global scope. Of course, of course, but so against best practices to be somewhat disgusting.
For the first part, simply declare the namespace in the library globally:
var Library = {};
and then start populating it with your modules:
Library.One = {}; Library.Two = {};
and then start adding functionality to these modules.
(function($) { var $.froobString = function(s) { .... }; ...etc... })(Library.One);
(Here I did it as a standalone executable anonymous function that runs in Library.One as $ .)
To convert all this to global, follow these steps:
var convertToGlobals = function(module) { for (name in module) { window[name] = module[name]; } }; convertToGlobals(Library.One)
But then I would advise you to do it.
source share