namespace

Topic description

Create an object in the specified space based on the package name

1  function namespace(oNamespace, sPackage) {
 2      var arr = sPackage.split('.' );
 3      var res = oNamespace;   // keep a reference to the original object 
4      for ( var i= 0 ,len=arr.length; i<len ;i++ ){
 5          if (arr[i] in oNamespace){ // The space name is in the object 
6              if ( typeof oNamespace[arr[i]] !== "object"){ // The property is not an object 
7                  oNamespace[arr[i]] = {} ; // make this property an empty object 
8              } 
 9          }
10          else {
 11              oNamespace[arr[i]] = {}; // The space name is not in the object, and this property is set to an empty object 
12          }
 13          oNamespace = oNamespace[arr[i]]; // Point the pointer down A space name attribute 
14      }
 15      return res;
 16 }

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325118370&siteId=291194637