2013-01-19 47 views
2

即时寻找jQuery应用程序体系结构的最佳实践。jQuery应用程序模式/体系结构

此示例正在工作,但我认为这不是一种最佳方式。

我们有内核函数(加载配置,init子模块等)和选项卡dub-module作为示例。

"use strict"; 
(function($, app, window) { 

    app.kernel = function() { 
     var self = this; 
     app.tabs().init(); // init tabs sub-module 
     return self; 
    }; 

    app.tabs = function() { 
     var self = this; 
     self.init = function() { 
      console.log('tabs function init'); 
     }; 
     return self; 

    }; 

})(jQuery, window.SuperPuper || (window.SuperPuper = {}), window); 

$(function() { 
    new SuperPuper.kernel(); 
}); 

成立一些材料:

  1. Using Inheritance Patterns to Organize Large jQuery Applications
  2. How To Write Maintainable jQuery Applications
+0

我的了解,jQuery是不是真的意味着然而http://davidjs.com/2011/07/jquery-extend-inheritance/建设类,有这个插件,似乎让复杂继承https://github.com/dfilatov/jquery-plugins/tree/master/src/jquery.inherit – mikakun

+0

当我使用jQuery完成“单页”应用程序时,我在功能块上分割应用程序,然后实现像jquery这样的块插件。插件可以通过插件方法调用和自定义事件进行通信。 http://docs.jquery.com/Plugins/Authoring –

回答