[Papervision3D] primitives

Nicolas Cannasse ncannasse at motion-twin.com
Thu Mar 1 03:47:32 EST 2007


> As a side note, I would think this would be perfectly fine:
> 
> if(blah) {
>    var abc;
> } else {
>    var abc;
> }
> 
> But apparently the compiler does not think those two {} blocks are in a
> separate scope, and warns about redefinition

Yes, that's a stupidity from ECMA languages : local variables are
declared in the function context, and there is no scoping at all.

For example in AS2 :

function f() {
    var x : Number = 0;
    if( true ) {
         var x : String = "hello";
    }
    trace(x); // "hello"
}

Of course, when the blocks are disjoint, you should be able to use the
same variable name, but in case the types are different that would cause
problems for AS3 since the same variable slot would be used.

haXe deals around this by renaming variables in order to ensure proper
scoping like in other languages.

Nicolas




More information about the Papervision3D mailing list