javascript 模块化 面向对象

静态方法1)2):

(function() {
    console.log("bbbb");
      /** Detect `this` as the global object. */
    var root = this;

    function getId(id){
            // return document.getElementById(id);
            console.log(id);
    };    

    function commonModule() {

    };
    commonModule.getId = getId;
    root.commonModule = commonModule;
}.call(this));



    commonModule.getId('weekView');

 

(function() {
    console.log("bbbb");
      /** Detect `this` as the global object. */

  var root = this;
    function commonModule() {

    };
    commonModule.getId = function(id){
            // return document.getElementById(id);
            console.log(id);
    };    
    root.commonModule = commonModule;
}.call(this));



    commonModule.getId('weekView');

 

 

https://github.com/NextSeason/jSwitch

https://github.com/search?utf8=%E2%9C%93&q=initialize+bindEvent&type=Code&ref=searchresults

J.Package( {
    initialize : function() {
        this.bindEvent();
    },
    bindEvent : function() {
        $( '.signout' ).on( 'click', function() {
            $.ajax( {

            } );
        } );
    }
} )

 

 http://www.ruanyifeng.com/blog/2010/05/object-oriented_javascript_encapsulation.html

  function Cat(name,color) {
    return {
      name:name,
      color:color
    }
  }

 

http://www.ruanyifeng.com/blog/2012/10/javascript_module.html

 

var module1 = (function(){
    var _count = 0;
    var m1 = function(){
      //...
    };
    var m2 = function(){
      //...
    };
    return {
      m1 : m1,
      m2 : m2
    };
  })();

 

posted @ 2016-08-16 17:43  lianhuaren  阅读(177)  评论(0)    收藏  举报