「公式」ドキュメントhttp://docs.jquery.com/Plugins/Authoring#Namespacingには、以下に示すように、メソッドをjQueryプラグインに追加する必要があると記載されています。このデザインパターンが頻繁に実装されるのを見たことがありません。他のプラグインがvarメソッドを使用している場合、競合が発生する可能性があります。これは本当に好ましい方法ですか、それとも別の方法で行う必要がありますか?
(function( $ ){
var methods = {
method1: function( options ) {},
method2: function( ) {}
};
$.fn.tooltip = function( method ) {
if ( methods[method] ) {
return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || ! method ) {
return methods.init.apply( this, arguments );
}
};
})( jQuery );