This content has been marked as final.
Show 4 replies
-
1. Re: checking function variable
Raymond Basque Mar 3, 2008 6:08 AM (in response to sneakyimp)Test against null.
if (serialize==null || unserialize==null){} -
2. Re: checking function variable
sneakyimp Mar 3, 2008 8:29 AM (in response to sneakyimp)Thanks for the response.
I fail to see why this usage would not invoke the function just like my original approach but apparently it does not. This seems really arbitrary to me. Is there any reason why this works and the other way does not? -
3. Re: checking function variable
Newsgroup_User Mar 3, 2008 8:53 AM (in response to sneakyimp)The functions are not being invoked -- it's the compiler doing type checking
and warning you of possible errors. The compiler sees functions in the
expression and is assuming you want return values from those functions.
You can use untyped references if you want to avoid the compiler warnings.
i.e.
private var serialize:*;
private var unserialize:*;
if (!serialize || !unserialize)
{
}
-
4. Re: checking function variable
sneakyimp Mar 3, 2008 9:32 AM (in response to sneakyimp)It occurred to me that what I really want to do is make sure this var is a function. After all, a scalar value like 3 that is not null would pass the test but wouldn't satisfy my need for a valid function.
I noticed in someone else's code the use of 'is' and a type. This code appears to be helpful for this:
var myFunc:Function;
if (myFunc is Function) {
trace('IS FUNCTION');
} else {
trace('IS NOT FUNCTION');
}
myFunc = Math.sin;
trace('assigned');
if (myFunc is Function) {
trace('IS FUNCTION');
} else {
trace('IS NOT FUNCTION');
}



