[技術/ExtJs] ExtJs 函式介紹: Ext.ns()

  • 9456
  • 0

Ext.ns, Ext.namespace

Reference: http://dev.sencha.com/deploy/dev/docs/source/Ext.html

Ext.ns() 的用法於官網描述如下:

/**
     * Creates namespaces to be used for scoping variables and classes so that they are not global.
     * Specifying the last node of a namespace implicitly creates all other nodes. Usage:
* /

Ext.namespace('Company', 'Company.data');
Ext.namespace('Company.data'); // equivalent and preferable to above syntax
Company.Widget = function() { ... }
Company.data.CustomStore = function(config) { ... }

     * @param {String} namespace1
     * @param {String} namespace2
     * @param {String} etc
     * @return {Object} The namespace object. (If multiple arguments are passed, this will be the last namespace created)
     * @method ns
     */


    Ext.ns = Ext.namespace;

})();

根據以上說明知道,Ext.ns 與 Ext.namespace 相同,
可使用 Ext.namespace(命名空間1, 命名空間2,...., 命名空間n) 建立多個類似在 .NET 中的 Namespace.


例如: 建立 Ext.util, Ext.lib, Ext.data 與 Ext.supports 等四個命名空間


Ext.ns('Ext.util', 'Ext.lib', 'Ext.data', 'Ext.supports'); 

另根據官網描述,若使用上述語法,會回傳以最後一個參數所建立的 Namespace object.



 




 

黑貓仔的修練之路