Notes:
- Moving names is good practice because you are less likely to have conflicting names with other scripts. Thus, only your namespace should be unique, but multiple namespaces can have the same functions in them.
- jQuery uses a namespace and you don't need a plugin. The jQuery object itself is a namespace. Any function inside jQuery is a name-distance in the jQuery object. This is true for any JavaScript object.
In response to Amir's comment:
YUI reaches the namespace by adding a variable to the YUI object, where the added variable is also an object. Their namespace function just builds it for you.
var lib = { util:{}, widget:{}, tool:{} };
In jQuery, you add it to jQuery.fn (or $.fn if you use the $ namespace for jQuery ().
source share