what is the point of void in AS3

折月煮酒 提交于 2019-12-20 05:57:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!