The best resource for creating a properly structured jQuery plugin is Plugins / Author Documentation . The part related to your post is the Namespacing section .
, add_selected_item , autoSuggest. , add_selected_item autoSuggest. undefined .
, jQuery. , " ":
(function( $ ){
var methods = {
init : function( options ) {
show : function( ) {
hide : function( ) {
update : function( content ) {
};
$.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 );
} else {
$.error( 'Method ' + method + ' does not exist on jQuery.tooltip' );
}
};
})( jQuery );
:
$('div').tooltip('hide');
$('div').tooltip('update', 'This is the new tooltip content!');
, :
(function($) {
var methods = {
init: function(data, options) {
},
add_selected_item: function(data, num) {
}
};
$.fn.autoSuggest = 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);
} else {
$.error('Method ' + method + ' does not exist on jQuery.autoSuggest');
}
};
})(jQuery);
. , . , .