我想知道如何在 jQuery 扩展中的方法之间共享数据,所以当我调用该方法时refresh,它能够使用.pluginoptionsinit
每页有多个这些控件。
这是我所拥有的一个例子:
(function($) {
    var methods = {
        init: function(options) {
            var defaults = {
                defaultText: "Rating",
                maxRating: 5,
            };
            options = $.extend(defaults, options);
            return this.each(function() {
                var plugin = $(this);
                main($(plugin), options);
            });
        },
        refresh: function() {
            // I would like to be able to use the 'options' and 'plugin' variables defined in the init method
        }
    };
    function main(plugin, option) {
        // do main code stuff
    }
}(jQuery));