[jQuery] Coding Design

[jQuery] Coding Design

Hi jQuery folks!
After having a look at the already very nice table sorter plugin by
Christian Bach, I wondered if his code (and mine, see below) could be
improved for performance by declaring all the stuff used by the plugin in
another way. Currently, all functions are declared for each table that the
plugin is applied to. While that may be optimized by the interpreters and
therefore only taken as declared once, I still think its not a good design.
Today I started working on my form validation plugin. I struggled with just
the same problems. My approach to find a nice solution was to read the
jQuery code, as that seemed to be a good reference. Based on the way how
jQuery is used and the different way how a plugin is used, I can't just copy
the concepts.
Could anyone write or post links on this topic?
What I'm heavily interessted in: How to structure your plugin code? Where to
place (private) 'helper functions'? Where should variables be saved? When is
it wise to use an object, and when should you instantiate it?
Currently, the jQuery.fn.plugin = function() {} syntax seems to be the only
reasonable thing that is provided for jQuery plugin developers. I think it
would be nice to have some more reference on how to design plugins.
Another suggestion in the docs is to put private functions into the $.
namespace (or that the object). I think thats not a good idea, because two
plugins could easily interfere there. My current version of the form
validation plugin has already about 6 oder 7 private functions, and while
I'll try to optimize that, that count may even increase.
If I need to start modifying third-party plugins I use, it would be tedious
to update those plugins.
Please, think of the puppies!
-- Jörn
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/