javascript library based on jquery
What would be the advice on starting and organising a library of useful code based on the jque开发者_如何学Pythonry 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.
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();
Well, start here: http://docs.jquery.com/Plugins/Authoring
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.
精彩评论