Scope modifiers: Difference between revisions

Content deleted Content added
m fixing tags
m →‎Variables: corrected requirements
Line 474:
Objects have an extra variable access mode. All the variables declared in a class definition are visible by default in the methods defined in that class. All other variable access modes are still available too.
 
{{works with|Tcl|8.6}} or {{libheader|TclOO}}
<lang tcl>oo::class create example {
# Note that this is otherwise syntactically the same as a local variable
Line 486:
}
[example new] showOff</lang>Output:<pre>variable objVar holds "This is an object variable"</pre>
 
===Commands===
Tcl commands are strictly always scoped to a particular namespace (defaulting to the global namespace, which is just a normal namespace in a somewhat privileged position). Commands are looked up in the current namespace first, then according to the current namespace's path rules (always empty prior to Tcl 8.5), and then finally in the global namespace. This effectively puts the global namespace in the scope of every namespace (though override-able in every namespace as well). By convention, library packages are placed in namespaces other than the global one (except for legacy cases or a single package access command) so that they don't cause unexpected conflicts; typically the global namespace is reserved for the Tcl language and user applications.