One thing I learnt recently is that just because you can use jQuery 
doesn't mean the innards of your plugin should be one big chain of 
jQuery methods.

For example, see Scott's Overlabel blog page...

Scott's original version used plain JS to do things, however it was a 
bit difficult to read:

http://scott.sauyet.com/thoughts/archives/2007/03/31/overlabel-with-jquery/

Then Dave came along with a jQuery version of the same code which was 
more compact and easier to read:

http://scott.sauyet.com/thoughts/archives/2007/03/31/overlabel-with-jquery/#comment-24144

Finally, Aristotle came along with a super-clean bit of JS that only 
used jQuery where it was absolutely necessary - this was far easier to 
read and as far as I can tell uses less method/function calls resulting 
in it also being a bit faster.

http://scott.sauyet.com/thoughts/archives/2007/03/31/overlabel-with-jquery/#comment-24205

While I resisted at first, Aristotle proved to me that clean JS should 
be used wherever possible to aid readability of the code. He helped me 
kick my method chaining addiction within plugin code :) Note: Chaining 
is still very useful for general jQuery use, but should only be used 
sparingly within the plugin itself if possible.

Aristotle also noted that it /might/ be better to use jQuery.fn.extend() 
to define functions:

http://scott.sauyet.com/thoughts/archives/2007/03/31/overlabel-with-jquery/#comment-24211

The comments system on the blog allowed other people to chip in with 
their own ideas, eg. support for JSF forms, support for existing forms 
where the HTML markup could not easily be changed, etc. The discussion 
enabled the plugin to be quickly polished to perfection (still some 
final tweaks to be made, eg. returning jQuery object to allow the method 
to be part of a chain).

Guy

Reply via email to