Developing jQuery Plug-ins

Lately I’ve been developing jQuery plug-ins in my spare time. Definitely go and check out the example pages. One of the main reasons for doing this is to get a grip of the latest API changes in jQuery.


Things I’ve learned

  • Make it chainable
    jQuery has many features, one of them is chainability. Which is the ability to chain one function after the other. The way to do this is by returning the original jQuery object.

    .css('color', '#ff0000');
  • Make it configurable
    Default options are OK, but make sure that people can modify the behavior without changing the actual code of the plug-in.

    "limit": 30,
      "service": "twitter",
      "user": "christianvuerings"
  • Make it extendible
    If someone do wants to add extra functionality to your plug-in, make sure they can. One way of doing this is by extending it.

    $.fn.lifestream.feeds.lastfm = function(obj, callback){
    // ...

A great resource is the jQuery authoring guide.

Christian Vuerings
Personal blog by Christian Vuerings
I love to share interesting ideas.