I'm trying to create typed functions using optional parameters sans the
defaults. I'm finding String to be the only thing that allows for null to be
passed. Is there a way to extend that functionality to other types like;
Numbers, Booleans, and/or ints?

NOTE : I am aware of ...rest and passing an object like what's used in
Tweener but that hides too much.


Thanks in advance,
Jesse



//      EXPECTED


        function test ( a:String = null ) 
        {
                trace( "test: " + ( a == null ) );
        }
        
        test ( "test" ); // false
        test ( ); // true <--- GOOD




//      UNFORTUNATE

                
        function test2 ( a:Boolean = false ) 
        {
                trace( "a: " + ( a == null ) );
        }
        test2 ( true ); // false
        test2 ( false ); // false
        test2 ( ); // false <--- BAD



//      IDEAL


        function test4 ( b:Boolean = null )
        {
                trace( b==null );
        }
        
        function test5 ( n:Number = null )
        {
                trace( isNaN(n) );
        }
        
        function test6 ( i:int = null ) 
        {
                trace( isNaN(i) );
        }

        test4 ( ); // true <--- DESIRED
        test5 ( ); // true <--- DESIRED
        test6 ( ); // true <--- DESIRED



//      CURRENT WORK AROUND -- ONLY WORKS WHEN NEEDING POSITIVES


        function test7 ( w:Number = -1, h:Number = -1 ) 
        {
                trace( (w < 0 || h < 0) );
        }

        test7 (10, 10); // false
        test7 (10); // true
        test7 (); // true

_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to