Reputation: 16152
Is it ever preferred to not declare the data type of the return value of a function?
Data type of return value is not declared:
function information(){
var myName:String="Mickey Mouse";
return myName;
}
trace(information());
Data type of return value is declared:
function information():String{
var myName:String="Mickey Mouse";
return myName;
}
trace(information());
Upvotes: 1
Views: 95
Reputation: 5978
Flex SDK compiler will consider the lack of return type as an error, so I guess this is pretty important :) If you need to have a function that returns several types of data:
:*
Upvotes: 1
Reputation: 179176
If you're programming along the lines of the ECMAScript variant of AS3, then it's completely unnecessary to specify a return type. The programmer should have a good idea of what sort of variable is being returned, and specifying the return type is "just a convenience".
Unfortunately, many of the core classes have been locked down using the final
keyword so that their prototypes aren't editable, nullifying many of the advantages that ECMAScript provides.
Upvotes: 1