actionscript 3 - Are parameters stored as local variables? -


pretty simple question here: parameters treated local variables, in terms of memory allocation?

for example take these 2 functions:

function foo(parameter:number):void     {         trace("parameter =", parameter);     }      function bar():void     {         var x:number;         trace("x number", x number);     } 

does actionscript handle both parameter , x in same way? both created local variables each time function run, , remain in existence until gc gets rid of them, or parameters treated differently?

does actionscript handle both parameter , x in same way? both created local variables each time function run, , remain in existence until gc gets rid of them, or parameters treated differently?

the runtime handles parameters little differently local variables, in end both local scope , cleaned when function returns. intents , purposes parameter local variable.

what's important understand how arguments passed functions work in as3.

in actionscript 3.0, arguments passed reference, because values stored objects. however, objects belong primitive data types, includes boolean, number, int, uint, , string, have special operators make them behave if passed value.

all other objects—that is, objects not belong primitive data types—are passed reference, gives ability change value of original variable.

in other words:

function test(primitive:int, complex:array):void {     primitive = 1;     complex.push("foo"); }  var i:int = 0; var a:array = []; test(i, a); trace(i); // 0 trace(a); // ["hi"] 

Comments