Ext中namespace的作用

Ext中在每一个页面中添加一个namespace呢,就像下面的代码:
 
  1. // create namespace  
  2. Ext.namespace('myNameSpace');  
  3.    
  4. // create application  
  5. myNameSpace.app = function() {  
  6.     // do NOT access DOM from here; elements don't exist yet  
  7.    
  8.     // private variables  
  9.    
  10.     // private functions  
  11.    
  12.     // public space  
  13.     return {  
  14.         // public properties, e.g. strings to translate  
  15.    
  16.         // public methods  
  17.         init: function() {  
  18.             alert('Application successfully initialized');  
  19.         }  
  20.     };  
  21. }(); // end of app  
作用呢就是用来封装一个global范围对象的属性和方法,以避免和其它的对象的属性和方法发生冲突,定义在return块中的方法和属性是公共的,外界可以直接访问,而其余的属性则不允许外界访问,通过这种方式,Ext较好的实现了在JavaScript中定义属性的public/private 问题。比较一下我在另外一篇blog中的js对象的private/public/protected的定义,就可以看出这种方法的好处:清晰。
  下面是Ext.nameSpace的API:
 
  1. namespace( String namespace1, String namespace2, String etc ) : void  
  2. Creates namespaces to be used for scoping variables and classes so that they are not global. Usage: Ext.namespace('C...  
  3. Creates namespaces to be used for scoping variables and classes so that they are not global. Usage:  
  4.   
  5. Ext.namespace('Company', 'Company.data');  
  6. Company.Widget = function() { ... }  
  7. Company.data.CustomStore = function(config) { ... }  
  8.   
  9. Parameters:  
  10.   
  11.     * namespace1 : String  
  12.     * namespace2 : String  
  13.     * etc : String  
  14.   
  15. Returns:  
  16.   
  17.     * void  

你可能感兴趣的:(JavaScript,C++,c,ext,Access)