Are you using jQuery.extend properly?
jQuery's
extend function is pretty powerful for merging objects and it is the hinge that plugins rely on to operate. It is very easy to use, but if you don't understand exactly what it does, it can come back and bite you.
The first case for using the method is to extend the jQuery object itself. Calling it on jQuery or jQuery.fn will add functions to the jQuery namespace or jQuery objects, respectively.
The second case is to merge objects together. You can do this by calling extend with multiple parameters. The first parameter is considered to be the base and all subsequent ones are merged into it in order. The updated object is also returned.
The important thing to be aware of is that the first parameter will be updated by this call. For example, if you have an object in your plugin that has its defaults stored in an object and you pass that in as the first argument, then it will by updated by the parameters passed in.
The wrong way to do it, causing your defaults to be rewritten:
[js]
var defaults = { some: 'option' };
function myPlugin(user_options) {
var options = $.extend(defaults, user_options);
...
}
[/js]
Instead, the safe way to call extend in that instance is like this:
[js]
var options = $.extend({}, defaults, user_options);
[/js]
That will cause the user options to override the defaults without rewriting them and store it in another variable for your use.