namespacing a plugin that imports multiple methods to the jQuery object

namespacing a plugin that imports multiple methods to the jQuery object


I have developed a plugin for working with tables. The plugin will
expose around ten methods to be used on a jQuery object (that contains
a table element), so I feel uncomfortable about polluting the
namespace with it. I am wondering if I should try to have a new table
object that inherits from the jQuery object, but I don't really know
how to accomplish that.
So far I have come up with the following idiom for namespacing, which
is kind of ugly.
$( selector ).table( "table_method", method_args )
This uses the following code
table_properties = { table_method : function( method_arg ){} ... }
jQuery.fn.table = function( method ){
return this.table[ method ].apply( this,
Array.prototype.slice.call( arguments, 1 ) );
}
jQuery.extend( jQuery.fn.table, table_properties );
I can still give the option to pollute the namespace with the
following code
jQuery.mixin_table = function(){
jQuery.each(table_properties, function(i) {
if(jQuery.fn[i] !== undefined) throw("collision");
jQuery.fn[i] = this;
});
}
jQuery.mixin_table(); //now $( selector ).table_method works directly
Any comments on what I am doing or recommendations for what I should
be doing would be greatly appreciated.