I have a stupid question. I got this variable:
var type:int;
and this function:
private function test(type:int):void {
}
when i call the function and throw in my variable type
test(type);
is there a possibility that the compiler gets confused because my variable has the same name like the functions’s parameter (type = type)? i’m not certain about this topic. Normally I’d write my function’s parameter like this (if such a case occurs):
private function test(_type:int):void
just to make sure the names do not exactly match (well I hope you know what I mean).
Nope.
test(type) will always refer to your variable named type and not to the parameter named type, because there is no access to the parameter variable outside of the function.
However, if within the test function you called test(type) at that point it would refer to the parameter variable type because local scope takes precedence (for the sake of the example let’s ignore the fact that calling test like that would cause the function to be called endlessly).
If you did want to refer to your global variable within the function you can always retrieve that by using the ‘this’ keyword.
Some examples: