只是一个例子:
(funciton($) {
var methods = {
init: function() {},
close: function() {},
open: function() {},
prev: function() {},
next: function() {},
};
$.fn.myplugin = function (method) {
if (methods[method]) {
return methods[method].apply(this, [].slice.call(arguments, 1));
} else if (typeof method == 'object' || !method) {
return methods.init.apply(this, arguments);
} else {
$.error( 'Method ' + method + ' does not exist on myplugin' );
}
};
}(jQuery));
//usage
$(selector).myplugin();
// call methods
$(selector).myplugin('close');
$(selector).myplugin('open');
$(selector).myplugin('next');
$(selector).myplugin('prev');