I’m working on a JQuery plugin. I want to define a statically visible method so I can access certain parts more easily. For instance, in C#, I would just do this:
public class MyPlugin()
{
public static string DoSomething(object parameter)
{
return DoImplementation();
}
}
However, I can’t figure out how to do this same type of thing in a JQuery plugin. Currently, I have the following:
(function ($) {
$.myPlugin = function (element, options) {
var defaults = {
average: 0
}
myPlugin.init = function () {
myPlugin.settings = $.extend({}, defaults, options);
}
myPlugin.doSomething = function (parameter) {
// Implementation goes here
}
}
})(jQuery);
How do I create a statically visible method from a JQuery plugin?
Thanks!
Obviously, this cannot go inside of the actual
myPluginfunction, since that function is per-“instance” (actually, per-call).The actual
myPluginmethod needs to be defined on$.fn(which is the prototype).