zoukankan      html  css  js  c++  java
  • 46. Ext中namespace的作用(转)

    转自:https://www.cnblogs.com/givemeanorange/p/5569954.html

    Ext中在每一个页面中添加一个namespace呢,就像下面的代码:

    复制代码
    // create namespace  
    Ext.namespace('myNameSpace');  
       
    // create application  
    myNameSpace.app = function() {  
        // do NOT access DOM from here; elements don't exist yet  
       
        // private variables  
       
        // private functions  
       
        // public space  
        return {  
            // public properties, e.g. strings to translate  
       
            // public methods  
            init: function() {  
                alert('Application successfully initialized');  
            }  
        };  
    }(); // end of app
    复制代码

    作用呢就是用来封装一个global范围对象的属性和方法,以避免和其它的对象的属性和方法发生冲突,定义在return块中的方法和属性是公共的,外界 可以直接访问,而其余的属性则不允许外界访问,通过这种方式,Ext较好的实现了在JavaScript中定义属性的public/private 问题。比较一下我在另外一篇blog中的js对象的private/public/protected的定义,就可以看出这种方法的好处:清晰。
      下面是Ext.nameSpace的API:

    复制代码
        namespace( String namespace1, String namespace2, String etc ) : void  
        Creates namespaces to be used for scoping variables and classes so that they are not global. Usage: Ext.namespace('C...  
        Creates namespaces to be used for scoping variables and classes so that they are not global. Usage:  
          
        Ext.namespace('Company', 'Company.data');  
        Company.Widget = function() { ... }  
        Company.data.CustomStore = function(config) { ... }  
          
        Parameters:  
          
            * namespace1 : String  
            * namespace2 : String  
            * etc : String  
          
        Returns:  
          
            * void  
  • 相关阅读:
    HDU 5912 Fraction (模拟)
    CodeForces 722C Destroying Array (并查集)
    CodeForces 722B Verse Pattern (水题)
    CodeForces 722A Broken Clock (水题)
    CodeForces 723D Lakes in Berland (dfs搜索)
    CodeForces 723C Polycarp at the Radio (题意题+暴力)
    CodeForces 723B Text Document Analysis (水题模拟)
    CodeForces 723A The New Year: Meeting Friends (水题)
    hdu 1258
    hdu 2266 dfs+1258
  • 原文地址:https://www.cnblogs.com/sharpest/p/7630376.html
Copyright © 2011-2022 走看看