One Plugin to end all jQuery Plugins



There is an small(ish) set of “official” jQuery plugins which are maintained by jQuery team. Consequently there is de-facto standard on what is a “good plugin”. And consequently to that there is a small list of “official” requirements for such a plugin. Each and every point in the list of “official” requirements for a good plugin one can be solve easily with the properly developed callback object, to be used by MetaPlugin.

This is one of the several possible valid callback object designs. Now let us see how is the callback object above solving the plugin requirements bellow.

  1. Claim only a single name in the jQuery namespace
    1. Solved, by using MetaPlugin
  2. Accept an options argument to control plugin behavior
    1. Using the callback as above this is easy (too).$("#toolbar").bbc( my_callback({ o1 : 1, o2: 2},":last") ;
  3. Provide public access to default plugin settings
    1. As made possible with the my_callback above. One just has to learn to use the callback object.// made here or somewhere else
      var callback = my_callback({ o1:1 })
      // just javascript
      var s1 = callback.default.s1
  4. Provide public access to secondary functions (as applicable)
    1. // just javascript
      callback.secondary() ;
  5. Keep private functions private
    1. As my_callback does…
  6. Support the Metadata Plugin
    1. As my_callback does, also

I thought it is better to have the solution for the “official” list of jQuery plugin requirements, here than in the comments bellow ;)
Of course one does not have to have all this “scafolding” to use MetaPlugin. Good old simple function will do, most of the time.