ActionScript 3 作用域内部细节介绍

ActionScript 3 的作用域使用对象链表来记录在作用域中的定义(变量、函数、类、接口和命名空间)。

● Class scope: the class's Class object (and the Class objects of the class's ancestors)

● Static method scope: the class's Class object (and the Class objects of the class's ancestors)

● Instance method scope: the current object (i.e., this) and an activation object (an "activation object" is an object created and stored internally by ActionScript for the purpose of maintaining the local variables and parameters of function or method)

● Function scope: an activation object

如下样例代码:

 1 package {
 2     public class SomeClass {
 3         public function instanceMeth():void {
 4             function nestedFunc():void {
 5                 trace(a);
 6             }
 7         }
 8     }
 9 }
10 var a:int = 15;

 

它的搜索过程为:

1、newstedFunc() 的 activation object

2、调用 instanceMeth() 的对象

3、SomeClass 的类对象

4、Object 的类对象(在搜索全局对象之前,它会先搜索 SomeClass 的父类,也就是 Object 的类)

5、全局对象

转载于:https://www.cnblogs.com/ezine/archive/2012/06/10/2544070.html

你可能感兴趣的:(ActionScript 3 作用域内部细节介绍)