-
Notifications
You must be signed in to change notification settings - Fork 243
"A Lightweight Start" Pattern
Joel Doyle edited this page Apr 12, 2016
·
2 revisions
From Learning JavaScript Design Patterns, a book by Addy Osmani.
Let’s begin our deeper look at plugin patterns with something basic that follows best practices (including those in the jQuery plugin-authoring guide). This pattern is ideal for developers who are either new to plugin development or who just want to achieve something simple (such as a utility plugin). A Lightweight Start uses the following:
- Common best practices such as a semi-colon placed before the functions invocation (we'll go through why in the comments below)
-
window, document, undefined
passed in as arguments. - A basic defaults object.
- A simple plugin constructor for logic related to the initial creation and the assignment of the element to * work with.
- Extending the options with defaults.
- A lightweight wrapper around the constructor, which helps to avoid issues such as multiple instantiations.
- Adherence to the jQuery core style guidelines for maximized readability.
- Plugins/Authoring, jQuery
- “Signs of a Poorly Written jQuery Plugin,” Remy Sharp
- “How to Create Your Own jQuery Plugin,” Elijah Manor
- “Style in jQuery Plugins and Why It Matters,” Ben Almon
- “Create Your First jQuery Plugin, Part 2,” Andrew Wirick