代码之家  ›  专栏  ›  技术社区  ›  Sajeeb Ahamed

维护大量函数jquery插件(最佳实践)

  •  0
  • Sajeeb Ahamed  · 技术社区  · 7 年前


    jQuery 插件。我正在跟踪这个结构-

    ;(function($, window, document, undefined){
        var name = "pluginName";
        function Plugin(element, options) {
            this.element    = element;
            this.name       = name;
            this._defaults  = $.fn.pluginName.defaults;
            this.options    = $.extend({}, this._defaults, options);
            this.init();
        }
    
        $.extend(Plugin.prototype, {
            init: function() {
    
            },
            otherFunctions: function() {
    
            }
            // and many other functions...
        });
    
        $.fn.pluginName = function(options) {
            this.each(function() {
                if (!$.data(this, name)) {
                    $.data(this, name, new Plugin(this, options));
                }
            });
            return this;
        }
    
        $.fn.pluginName.defaults = {
            // Default plugin values
        };
    
    
    })(jQuery, window, document);
    

    请注意评论 // and many other functions...
    那么有没有任何方法或程序来维护这些数量众多的函数,我的意思是,这将是维护这些数量众多的函数的最佳实践。

    0 回复  |  直到 7 年前