According to jquery developer documentation, plugins should have only one namespace for all the functions they provide. This is straightforward if you use only one function for each context (static / element).
(function($){
var
state_a = 0,
$.myplugin = function(in_options) {
return this;
}
$.fn.myplugin = function(in_options) {
return this;
}
})(jQuery);
This makes calls like this:
$("elem").myplugin(options);
jQuery.myplugin(options);
What is the best approach if you have more than one function and need to share the state? I would like to call my plugin as follows:
$("elem").myplugin.start(options);
$("elem").myplugin.stop();
jQuery.myplugin.start(options);
jQuery.myplugin.stop();
source
share