-
Declare variables referenced in enterframe at function or class level?
Hi,
If i have a series of variables that are referenced on an enter frame function, is it better to declare the frequently used vars at the class level? Is there a performance benefit? What is the standard?
Example
PHP Code:
public class Animation extends Sprite{
private var num:int;
public function Animation(){ }
private function happensOnEnterFrame():void{ num = transformation // do other things with num... }
}
...as opposed to...
PHP Code:
public class Animation extends Sprite{
public function Animation(){ }
private function happensOnEnterFrame():void{ var num:int num = transformation // do other things with num... }
}
-
Personally, unless num needs to be used outside of that function, I would declare it inside. Why clutter up the class with properties that are used in only a single place?
I haven't tested, but I would also expect the local variable to be slightly faster as it's in a narrower (and thus resolved earlier) scope.
-
Thanks flax, I thought that perhaps if the variable was only declared only once at the class level instead of being redeclared every time the enterFrame function was called, there might be a performance benefit although likely infinitesimal. The points about cluttering the class and possible speed benefit due to local scope make sense.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|