问题
Simple question here, when void follows a function in AS3 what is it doing?
public function sayGoodbye():void { trace("Goodbye from MySubClass");}
回答1:
void type indicates to the compiler that the function you have written will not return any value, in the other side if you indicate other type T than void the compiler expect that you return T.
Ex:
function foo(a:int):int { // here the compiler expect that somewhere
// in your function you return an int
return a;
}
回答2:
void means that it has no return value. I.e., you can't use it in an expression.
回答3:
void specifies that the function will return no value, or, to be more exact, the special undefined value type. Note that the function return can be used in an expression and it is the unique value of the undefined type.
In actionscript 3 to conform to the strict mode you need to specify variable types and function return types in order for the compiler to know what types to expect and to optimize your application.
来源:https://stackoverflow.com/questions/4280132/what-is-the-point-of-void-in-as3