A jQuery Plugin Development Pattern
I’ve been developing jQuery plugins for quite a while now, and I’ve become rather comfortable with a particular style of plugin development for my scripts. This article is meant to share the pattern that I’ve found especially useful for plugin authoring. It assumes you already have an understanding of plugin development for jQuery; if you’re a novice plugin author, please review the jQuery Authoring Guidelines first.
There are a few requirements that I feel this pattern handles nicely:
1. Claim only a single name in the jQuery namespace
2. Accept an options argument to control plugin behavior
3. Provide public access to default plugin settings
4. Provide public access to secondary functions (as applicable)
5. Keep private functions private
6. Support the Metadata Plugin
I’ll cover these requirements one by one, and as we work through them we’ll build a simple plugin which highlights text.