类的定义对名字空间玩弄了一些小技巧,为了全面了解所发生的事情,你必须了解作用域与名字空间的工作方式。
Class definitions play some neat tricks with namespaces and you need to know how scopes and namespaces work to fully understand what's going on.
当输入了一个类定义,一个新的名字空间被创建,并作为局部域使用——这样,所有对局部变量的赋值都将进入这个新的名字空间。
When a class definition is entered a new namespace is created and used as the local scope - thus all assignments to local variables go into this new namespace.
在函数之外,局部作用域引用全局作用域相同的名字空间:模块的名字空间。
Outside functions the local scope references the same namespace as the global scope: the module's namespace.
应用推荐