(function ( $ ) {
$.fn.greenify = function( options ) {
// This is the easiest way to have default options.
var settings = $.extend({
// These are the defaults.
color: "#556b2f",
backgroundColor: "white"
}, options );
// Greenify the collection based on the settings variable.
return this.css({
color: settings.color,
backgroundColor: settings.backgroundColor
});
};
}( jQuery ));
Taken from Docs the above code shows how to make a simple jquery plugin. What if I only supply one of multiple parameters listed in a plugin that accepts multiple? Which ones are applied?
If I have a plugin that can take multiple parameters, which ones will be applied in something like this:
$.doStuff({color:"black"},{color:"blue"});
What set of options will be "extended" when only one set of parameters if supplied?
E.x. $.doStuff({color:"black"});