我注意到在函数的返回类型中,可以使用'Void'或者'void',我想知道这两者是否有区别或者优劣之分?
我注意到在函数的返回类型中,可以使用'Void'或者'void',我想知道这两者是否有区别或者优劣之分?
Void
(大写的“V”)是ActionScript 2版本中与ActionScript 3的void
相对应的类型。
AS3文档(void):
指定函数不能返回任何值。 void
类型是一个特殊类型,只包含一个值:undefined。它的使用限制于函数的返回类型。您不能将void
用作属性的类型注释。
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/specialTypes.html#void
AS2文档(Void):
Void
数据类型只有一个值,void,在函数定义中用来表示函数不返回任何值,如下面的例子所示:
//Creates a function with a return type Void
function displayFromURL(url:String):Void {}
http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00000037.html
void类型表示编译器所写的函数将不返回任何值,另一方面,如果您指定除void以外的其他类型(如int),则编译器会期望您返回该类型。
例如:
function foo(a:int):int
{
// here the compiler expect that somewhere
// in your function you return an int
return a;
}
AS2 = :Void
AS3 = :void