jQueryjQuery offers a fully-extensible framework for adding in new methods and functionality. Most of the plugins included in the default download are written using the jQuery plugin construct.
Plug-in writing comes in two steps. The first is writing any of your public methods, for example:
$.fn.debug = function() {
return this.each(function(){
alert(this);
});
};
Coders will now be able to call your new plugin, like so:
$("div p").debug();
There are a couple of very important points to remember:
If you need to write any private methods (ones that the end-coder doesn't need to see), you can feel free to bind them to the $ object itself, for example:
$.test = function() {
// Do some internal stuff
};
You can then access it in the same manner:
$.test("some stuff");
We recommend that you do it this way so that your code doesn't accidentally overwrite any other functions that the user may be using.
If you're curious as to how a full module looks, feel free to Browse the Source Code