JavaScript Namespace

后端 未结 11 1487
暗喜
暗喜 2020-12-15 07:25

I want to create a global namespace for my application and in that namespace I want other namespaces:

E.g.

Dashboard.Ajax.Post()

Dashboard.RetrieveC         


        
11条回答
  •  爱一瞬间的悲伤
    2020-12-15 07:58

    You just need to make sure that you don't stomp on your namespace object if it's already been created. Something like this would work:

    (function() {
        // private vars can go in here
    
    
        Dashboard = Dashboard || {};
        Dashboard.Ajax = {
            Post: function() {
                ...
            }
        };
    })();
    

    And the RetrieveContent file would be defined similarly.

提交回复
热议问题