PDA

View Full Version : Complex objects as default parameters?


pan69
07-23-2008, 12:58 AM
Anyone knows if it is possible to have complex objects as default parameters? All the documentation I can find talks about primitives like int & string.


function booking( date : Date = new Date() ) : void
{
}

CobaltBlueDW
07-23-2008, 03:28 AM
I would be shocked if you couldn't, but I doubt you could create the object in the parameter list.

Just do this:

function booking(date:Date=null){
if(date == null) date = new Date();


}


that is better code anyway because it detects if the caller sends in a null as well.

pan69
07-23-2008, 07:49 AM
Unfortunately I'm not shocked about this. Disappointed, yes.

that is better code anyway because it detects if the caller sends in a null as well.

true.

Cheers!

Flash Gordon
07-23-2008, 08:16 AM
yup. agreed with the null approach.