AS3's got some awkward rules about variable scope, due to its use of hoisting. I don't like pointlessly leaving a bunch of compiler warnings lying around, but it's more important to me for my code to readable and properly written, regardless. This produces a couple of duplicate variable definition warnings:
private function arrangeElementsLine(pElementSize:Dimensions):void
{
if (m_eOrientation == HORIZONTAL)
{
for (var i:uint = 0; i < target.numElements; i++)
{
var layoutElement:ILayoutElement = target.getElementAt(i);
layoutElement.setLayoutBoundsSize(pElementSize.x, pElementSize.y);
layoutElement.setLayoutBoundsPosition(pElementSize.x * i, 0);
}
}
else
{
for (var i:uint = 0; i < target.numElements; i++)
{
var layoutElement:ILayoutElement = target.getElementAt(i);
layoutElement.setLayoutBoundsSize(pElementSize.x, pElementSize.y);
layoutElement.setLayoutBoundsPosition(0, pElementSize.y * i);
}
}
}
Is it generally considered to be better and more conventional to remove the redundant var
and :<type>
syntax for i
and layoutElement
in the second for
loop, or is it more proper to just leave them in there (due to the way their usage is isolated to those two for
loops)? Thanks!
EDIT
This was asked a while back, but when I asked this, part of what I was working on was making something run more efficiently; so I put if
outside of any for
statements and avoided method calls inside the for
statements.