Declaring variable in loop or before loop in AS3?
Should I declare the _mcContainer var befo开发者_如何学JAVAre the loop or no? (performance increase?)
for(var i:uint = _startIndex; i <= _endIndex; ++i){
var _mcContainer:MovieClip = _mcParent["i_" + _position];
}
or
var _mcContainer:MovieClip;
for(var i:uint = _startIndex; i <= _endIndex; ++i){
_mcContainer = _mcParent["i_" + _position];
}
?
It's not hard to test...
...however according to the docs, it shouldn't make any difference because variable declarations are hoisted to the top of the method block anyway.
From 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.
精彩评论