问题描述
考虑一个。如
文件,该文件是这样的:
Consider a .as
file which looks like this:
package foo {
class Foo {
public static var a:* = getA();
public static var b:* = getB();
public var c:* = getC();
public static function d():* { ... }
public function Foo() {
trace("initializing");
}
}
}
// internal functions/variables
var e:* = getD();
function f():* { ... }
什么是用于初始化每个变量/函数定义的顺序 A..F
?
(我知道我可以做实验,找出...但是我正在寻找的实际指定的定义)
(I know I can do experiments to find out… But I'm looking for the actual specified definition)
推荐答案
那么,棘手的部分是静态初始化。
Well, the tricky part is static initialization.
所有的静态方法和变量之前执行的任何声明。静态方法是瞬间初始化,因为你可以随时打电话给他们的感觉。然后,静态变量出现的顺序初始化。然后,所有静态初始化是为了appearence的执行:
All static methods and variables are declared prior to any execution. Static methods are "instantly" initialized, in the sense that you can call them at any time. Then static variables are initialized in order of appearance. Then all static initialization is performed in order of appearence:
package {
import flash.display.Sprite;
public class Main extends Sprite {
__init(c,'static');//"static initialization b" because all variables are initialized prior to static initialization
public static var a:String = __init(b);//"variable initialization null", because b is declared, but not initialized
public static var b:String = __init('b');//"variable initialization b" for obvious reasons
public static var c:String = __init(b);//"variable initialization b" because b is now initialized
public static function __init(s:String, type:String = 'variable'):String {
trace(type, 'initialization', s);
return s;
}
public function Main():void {}
}
}
但总的来说,我的建议是不依赖于它,除非你的真正的需要。
这篇关于动作:什么是用于初始化内部/静态/实例变量定义的顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!