[Flashcoders] [AS3] optional parameters - sans defaults for Boolean/Number/int

2008-02-29 Thread Jesse Graupmann
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


Re: [Flashcoders] [AS3] optional parameters - sans defaults for Boolean/Number/int

2008-02-29 Thread Glen Pike

Hi,

   You can have * to specify any parameter:

   function myFunc(param1:Boolean, param2:*);

Matthew Houliston wrote:

don't you mean

function test2 ( a:Boolean = false )
{
trace( a:  + ( a == true ) );
}

?


A Boolean is never null.

var b:Boolean;
trace(b);



On 29/02/2008 10:42, Jesse Graupmann wrote:

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



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




--

Glen Pike
01736 759321
www.glenpike.co.uk http://www.glenpike.co.uk
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders