Tcl Built-In Commands - namespace manual page:: the contents of a namespace over time using a series of namespace eval commands. You can use the namespace which command to clear up any question about http://www.tcl.tk/man/tcl8.3/TclCmd/namespace.htmHOME | I read the tutorial about the usage of namespace but I didnt undertand it.
1. Ext says that namespace is useful to avoid creating global variables or classes, right?
2. So if I do the next:
Ext.namespace("MyClass");
MyClass= function(){
this.variable=....... XML Namespaces:: When using prefixes in XML, a so-called namespace for the prefix must be defined. The namespace is defined by the xmlns attribute in the start tag of an element. http://www.w3schools.com/xml/xml_namespaces.aspHOME |
}
MyClass is not a global function?
Thanks
Namespaces in JS are simulated, they're just nested objects.
1) Yes
2) Yes
3) Correct
I read that the namespace is for avoiding to override classes with the same name like the next example: #81 (Problems with use default namespace public) – ECMAScript Bugs – Trac:: If I add use default namespace public inside the !MathInternals package, and in a context where P.f is an import, or using ns::f for some dynamic value of ns. http://bugs.ecmascript.org/ticket/81HOME |
Ext.ns("MyClass");
Ext.ns("HisClass");
MyClass.subclass1= function(){
....
}
HisClass.subclass1= function(){
.....
}
1. I have two classes ("subclass1") named equal but with different namespace, right?
2. All declared in the form MyClass.something would be local to the namespace MyClass, right?
3. Its like declaring packages in java? tries to simulate this?
Thanks
Only the top-level namespace becomes a global variable, e.g.
Ext.ns('MyNamespace.subns');
MyNamespace.MyClass1 = function() {...};
MyNamespace.MyClass2 = function() {...};
MyNamespace.subns.MyClass3 = function() {...};
For example if I do:
Ext.namespace("MyClass");
MyClass.subclass1= function(){....}
1. MyClass would be global but MyClass.subclass1 wouldnt, right?
2. If I wouldnt use Ext.namespace(....), MyClass.subclass1 would be global, right?
3. Why wouldnt I want MyClass.subclass1 to be global?
Thanks
1) Yes
2) No
3) That's the whole point of using a namespace, so you can separate out your code and not pollute the global namespace.
Say you did
Ext.ns('Foo.Bar.Baz');
It's equivalent to
Foo = {};
Foo.Bar = {};
Foo.Bar.Baz = {};
Nortel Unveils Vision, Strategy for Israeli High-Performance Net
Busy Friday Leads to Strong Close for Net Stocks
|