gpt4 book ai didi

actionscript-3 - 在AS3中在循环中或循环前声明变量?

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

我应该在循环之前声明 _mcContainer var 还是不声明? (性能提升?)

for(var i:uint = _startIndex; i <= _endIndex; ++i){    
var _mcContainer:MovieClip = _mcParent["i_" + _position];
}

var _mcContainer:MovieClip;
for(var i:uint = _startIndex; i <= _endIndex; ++i){
_mcContainer = _mcParent["i_" + _position];
}

最佳答案

测试并不难...

...但是根据文档,它应该没有任何区别,因为变量声明无论如何都会被提升到方法 block 的顶部。

来自the docs :

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.

关于actionscript-3 - 在AS3中在循环中或循环前声明变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4136338/

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