问题
What is the use of void
in Action Script 3.0?
Can any one give brief explanation with example?
回答1:
It's a function type. It means that it doesn't return any data By default Flash always expect to return a value. If you write a function like this for example: ActionScript Code:
function myFunction(){
}
Flash assumes that returning a value is still possible and so watch for it which uses ressources. When you specify :void you are actually telling Flash to not expect any return value so Flash does not waste resources watching for it.
回答2:
void is an actionscript keyword, used to define no return type in function signature, and force compiler to ristrict/check it
eg
public function func():void
{
//do some thing
}
above function retuns nothing
Hopefully this will helps
回答3:
Easiest way for me to remember it is that it is a function that carries out an action (in other words does something) rather than returns something.
Example:
function myFunction(event:MouseEvent): void
{ this.play; //or some other action}
//the above function returns nothing
function mySum(a:int, b:int): int
{var myresult:int = a+b;
return myresult;}
//the above function would return the sum of two integers that you passed into it
来源:https://stackoverflow.com/questions/5591580/what-is-the-use-of-void-in-as3