jQuery Boilerplate Question about $.data()

I’ve been looking at jQuery Boilerplate and really like it; it makes good sense.

Towards the end you have:

// A really lightweight plugin wrapper around the constructor,
// preventing against multiple instantiations
$.fn[ pluginName ] = function ( options ) {
        return this.each(function() {
                if ( !$.data( this, "plugin_" + pluginName ) ) {
                        $.data( this, "plugin_" + pluginName, new Plugin( this, options ) );

I get that it prevents multiple instantiations but isn’t the another good reason so you can more easily access certain matched elements. E.g. You could do:

    propertyName: "a custom value"


So you don’t need to return defaultPluginName to a variable and then filter; you can access any of the elements you want directly using data.

I’m still new to this, just trying to get my head around the reasoning behind it.

Finally, why is ( jQuery, window, document ) at the end rather than just (jQuery)? I know window and document are passed to speed things up but why have it at the end too?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.