Can anyone explain to me please that if using a namespace is a good coding practice. And why is it needed? If it was a good approach why JQuery didn't include it by default. There is a separate plugin to allow this functionality.
I saw this post that mentions few ways to do it. Someone mentioned about memory leak in the post that is worrisome.
Lastly, what is the best way to organize JQuery libraries?
thanks,
Notes:
In response to Amir's comment:
YUI achieves namespacing 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:{}
};
//creates a function named reset in the lib.util namespace
lib.util.reset = function() {};
//creates a function named reset in the lib.widget namespace
lib.widget.reset = function() {};
In jQuery, you add it to the jQuery.fn
(or $.fn
if you use $
for jQuery() namespace.
Re: best ways to organize jQuery libraries, you should start by reading the Plugins Authoring article on jquery.com:
http://docs.jquery.com/Plugins/Authoring
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With