On 3/13/07, Jörn Zaefferer <[EMAIL PROTECTED]> wrote:
> Brandon Aaron schrieb:
> > I thought about this approach as well but then you gotta think that
> > this is a plugin that others will use and possibly other plugins might
> > depend on it as well. Then if the defaults changed, the plugin that
> > depends on it could be confused and break. It is easy enough for a
> > devloper to setup their own set of defaults that would not cause an
> > issue like this.
> >
> > var myHoverDefaults = { interval: 250 };
> >
> > Now just pass that in and your set and don't potentially break any
> > other plugins.
> >
> > As an example ... I'm updating my bgiframe plugin to accept an options
> > hash. If I allowed a developer/plugin to change the defaults then all
> > the plugins that depend on the defaults would then break.
> >
> > Hopefully that all made sense ... I'm writing it in a bit of a rush.
> >
> Err, maybe, maybe not. Either way, I had a big mistake in my code
> example. Corrected:
>
> jQuery.fn.hoverIntent = function (on,off,options) {
>    var settings = jQuery.extend({}, jQuery.hoverIntent.defaults, options);
>    ...
> };
> jQuery.hoverIntent = {};
> jQuery.extend(jQuery.hoverIntent, {
>         defaults: { sensitivity: 4, interval: 100 },
>         setDefaults: function(settings) {
>                 jQuery.extend(jQuery.hoverIntent.defaults, settings);
>          }
> });
>
> I hope that makes more sense.

Maybe I can make more sense today ... hopefully. Lets say I had a
plugin that depended on this plugin and I changed the defaults in my
plugin. Now when the developer includes my plugin, the defaults have
been changed and the expected behavior of the plugin is different.
That would be very frustrating as a plugin developer and a developer
using the plugins.

My plugin:
...
jQuery.hoverIntent.defaults = { sensitivity: 10, interval 500 };
...

Now, my plugin depends on those "defaults" and the developer has
changed the defaults to something completely different. Of course as a
plugin developer I could *not* depend on the defaults but they
shouldn't be called defaults then. I believe it is best to keep the
defaults internal and not allow others to change the defaults for all
implementations of the plugin. It could also be a problem if the
defaults have been changed on a very big project with lots of
developers. I don't think it is a good idea to have a general
setDefaults function either unless it was per an instance based, not
global for the plugin.

Hopefully that made more sense.

--
Brandon Aaron

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to