int and uint default values are NOT null
Write it down because it's going to leave you o_O the moment you want to use them. Let's say you have an object that can be sized from 1 to whatever, that's clearly a uint type. Let's say you want to make life easier for your users (developers using your API in this case) and you want to write something like this:
[code lang="actionscript"]
setSize(width:unit=null,height:uint=null):void{
if(width != null){ // do something; }
if(height != null){ // do other something; }
}
[/code]
The idea is that whoever is calling the function can set a new width or height without passing the other. Like this:
[code lang="actionscript"]
setSize(100);
setSize(null,100)
[/code]
Well, it doesn't work. Default value for int and unit is 0 (zero). I'm sure there's a super-geeky explanation out there about why (although I haven't been able to find it in Moock's book) but the fact is that this seems weird.
So you are left with either:
a) handle 0 as the default value, which is weird to me.
b) make the 2 parameters mandatory, which is "annoying" for the users.
I think I'm going to stick with option b).
And just for the record, the default value of Number property is NaN and if you want to check if a number is NaN you have to do it like this:
[code lang="actionscript"]
if(isNaN(myVar)){ //wadus }
[/code]
Back to index