gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 01:45:24 26 4
gpt4 key购买 nike

受到问题的启发 int a[] = {1,2,}; Weird comma allowed. Any particular reason?我记得有一个关于 Adob​​e Actionscript 语法的问题。

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

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

这有道理吗..?这是 Adob​​e 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:为什么可以在声明之前分配变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7045410/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com