If I want to have a publicly accessible function on a jQuery plugin I’m making, is this the proper way to do it?
(function($) {
$.fn.myPlug = function(options) {
// Do this...
this.hello = function() {
return 1;
};
}
})(jQuery);
var foo = $("div").myPlug();
// then do this...
foo.hello();
You should structure your plugin so that method names can be passed as parameters to your plugin. This is recommended by the jQuery plugin authoring guide:
The usage would go something like this: