flash – Actionscript:为什么可以在声明之前分配一个变量?

灵感来自于int a[] = {1,2,}; Weird comma allowed. Any particular reason?的问题,我记得有关Adobe的Actionscript语法的问题.

由于某种原因,有可能(至少在Flex 3中)在声明之前为变量赋值:

 public function foo() : void {
      a = 3;
      var a : int = 0;

这有什么意义吗?这是Adobe FlexBuilder编译器中的错误吗?或者这是否可能是旧的Ecmascript版本的一些遗产?

An interesting implication of the lack of block-level scope is that you can read or write to a variable before it is declared, as long as it is declared before the function ends. This is because of a technique called hoisting , which means that the compiler moves all variable declarations to the top of the function. For example, the following code compiles even though the initial trace() function for the num variable happens before the num variable is declared…

Actionscript 3.0 Docs – Variables(报价发现约2/3页)

转载注明原文:flash – Actionscript:为什么可以在声明之前分配一个变量? - 代码日志