Writing jQuery Plug-Ins
For many developers, the process of creating dynamic websites or AJAX-style applications begins and ends with jQuery. There’s no doubt at all that jQuery is an incredibly useful library, but it’s very easy—and tempting—to simply keep writing procedural-style jQuery calls and do without all of the things that jQuery doesn’t provide the facilities to do.
This chapter looks at the development of jQuery plug-ins with CoffeeScript in both a procedural and object-oriented fashion and how jQuery UI widgets can be created. Either of these frameworks can be used to create new interactive interface elements, but there are some basic differences in how they work and the fundamental architecture.
Anatomy of a jQuery plug-in
When the jQuery library was first published, it was seen as a compatibility library—a kind of shim that developers could use to smooth over the various cracks in different browsers so that they could get on with the real work of developing web applications.
It didn’t take long, though, for other developers to start adding functionality to jQuery, and in fact the first plug-in ...