JavaScript Namespace

           
    JavaScript Namespace        
            
    With the prevailing usage of AJAX calls, multiple subapps (and their corresponding JS snippets) will be loaded in the same logical "page", thus sharing the same runtime namespace.        
    Without proper naming control, there's a high chance of different subapps having functions and variable naming conflicts, when they are "weaved" fo        
    Therefore, it is imperative that we have proper namespace management for our javascript functions, both for common js library, and for subapp js        
            
    All subapps are implicitly importing and inheriting the following "objects"        
            
            
    Javascript my itself does not have the concept of namespace.        
    However, we can achieve the effect of non-conflicting namespace by following a coding pattern.        
    For us, the following pattern is proposed.        
            
    All Javascript fields and function definitions must be defined this way (assuming subapp name is TestSubapp):        
            
    var TestSubapp = new function() {        
        this.var1 = "";    
        this.function1 = function() {    
            return 12345;
        };    
    }        
            
    Instead of placing your variables and functions in the global namespace, a virtual namespace "TestSubapp" is simulated.        
    The virtual namespace will take the naming convention of CamelCase, using the name of the subapp.        
            
    Variables and functions declared this way can be accessed using:        
    TestSubapp.var1 = TestSubapp.function();        
            
            
    The following namespace are provided at framework level, and are automatically available to subapps        

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值