Senchatouch uses a namespace similar to a Java package to hide something. This prevents all variables from being changed to global variables.
However, when you name a variable, you 'd better use the VaR keyword. If you do not declare the variable with the VaR keyword, your variable will be the global variable under the window by default.
However, the use of closures can also play an effect, but I have never tried it. It is such a function declaration (function (){})();
The following describes how to use a namespace. Ext. NS () is short for Ext. namespace () and is used to declare a namespace.
In fact, just getting familiar with the Javascript syntax knows that there is no such thing at all. In fact, ext only simulates the namespace (or package) by using similar usage of attributes added to the object ). Because the object or method is a closure, the variables defined in it are closed to the outside world.
Ext. NS ('myspace '); // It is equivalent to defining an empty function object (or think it is a class) and can be written as MySpace = ext. emtyfn (); or MySpace = {}
MySpace. APP = ext. Panel ({}); // This MySpace. app adds an attribute to the MySpace object and the attribute name is app (it is a function object of the Panel ).
If Ext. NS ('myspace ', 'myspace. data', 'myspace. views '); // you define three objects, MySpace, and MySpace data. The views attribute is an object, so you can access MySpace. data. moumou to add the attributes of this object.
Ext. another feature of NS () is Ext. NS ('myspace. data. box '); with ext. NS ('myspace ', 'myspace. data', 'myspace. data. box ') is the same. In addition, if you define a namespace, if you put it in the first JS, everything in the namespace will be valid before you, no, but declared and not defined. Because before that, your attributes are already in front (as mentioned in the namespace, if used, they are assigned a value before the namespace ).
Using namespaces, you can divide views, data, and class into different JS files and place them in different folders. This makes the code clearer and more clean, and facilitates maintenance and changes.