Providing default values
It is a good practice to provide configurable items in plugin methods to enable developers to customize according to the requirements of their application. The use of an options
object enables us to achieve this. A default set of options can also be provided so that developers can selectively override the configurations that they want.
In this example, let's build the plugin created in the previous recipe to provide the options object as well as provide a map of default values.
The constructs used in this example are summarized as follows:
Construct |
Type |
Description |
---|---|---|
|
jQuery function |
This refers to the jQuery function. |
|
jQuery selector |
This selects an element based on its ID. |
|
jQuery object |
This refers to the current jQuery object. |
|
jQuery function |
This merges the contents of two or more objects into the first object. |
|
jQuery method |
This gets the style property for the first... |