views:

57

answers:

3

What would be the advice on starting and organising a library of useful code based on the jquery library?

Im thinking of starting this for all of the code that I use alot and ends up just being copied and pasted between projects.

I would like to have all of this functionality included in some sort of library of plugins?

Any ideas or best practices in this area?

EDIT: A lot of advice here is with regards to creating plugins - thats proving to be helpful. Although, what i was really interested in is how to organise all of the plugins in one placce where i can simply call any piece of functionality whenever its required.

A: 

Well, start here: http://docs.jquery.com/Plugins/Authoring

wybiral
A: 

If you're thinking of this as a time-saver for your own uses, then it's a great idea. Every developer should take time to build up their own personal toolkit of functions / classes / plug-ins / etc that they use over and over.

If you're thinking of it as something to share with others, it may be a harder sell. You say you want to create a library of plug-ins, but in fact the jquery site already has such a library. Being hosted on the jquery site itself gives it a lot of credibility, so anyone searching for a plug-in would naturally gravitate towards it before looking anywhere else, which means that your third-party library would be somewhat overshadowed.

Spudley
Hi, yes this is definately something to save me time as opposed to anything else external
Bob
A: 

If your library functions are completely dependent on jQuery (using either the $.fn.myFunc, for utility functions, or the $.myFunc style), then just implement your plugins as jQuery plugins. However, if you are just looking for a jQuery-like $.fn.myFunc framework, in which you only have utility functions, then just create your own namespace for your library functions like this:

MyNamespace = {};

MyNamespace.MyFunc = function(){


};

And then use your functions like this:

MyNamespace.MyFunc();
SimpleCoder
I have accepted your answer as it most cloesely answers my question, although I was hoping for some more advice from members on the code organisation aspect. Thank you though.
Bob
Sure! As for code organization, I would suggest putting individual plugins (or groups of similar plugins) into separate files, like modules. In each module, you should create the `MyNamespace` namespace if it doesn't exist, like this: `MyNamespace = {};`. Then, you can safely include only the modules you need.
SimpleCoder