Individual Entry

Void与void的差别

Void和void同是flash中的关键字,但是他们之间存在差别。
首先Void是一种特殊的类型,因此函数可以是Void型的。之所以说Void特殊,是因为没有Void型的变量。
比如下面的代码:
var k:Void;
//error:A variable may not be of type Void.
Void型的函数表示不返回任何类型的对象。
function myfunc(Void):Void {
}
假如有看过as2lib包内的类文件,里面经常可以看到类似上面的语句,参数为Void表示无参数。
void很少单独使用(我想应该有单独使用的例子,但是很遗憾我没有找到),void(x)表示忽略x的值返回undefined。
如果函数参数省略Void:
function myfunc():Void{
trace(arguments[0]);
}
myfunc(12);
//output:12
则可以接受任何参数,而且个数不限。有时为了模拟方法重载所以会省略Void

3 comments:

有多学了点东西,原来function缺省参数和Viod参数是这样的。加个连接可以吗?我的http://spaces.msn.com/membe...
等待你的同意~:)
by: iiley (contact) - 12 May '05 - 15:30
已经添加您的连接
by: greentea (contact) - 13 May '05 - 18:26
谢谢~;]
by: iiley (contact) - 13 May '05 - 19:02



:

:
:



Meta Information:

Title: Void与void的差别
Date posted: 04 May '05 - 12:11
Filed under: actionscript
Wordcount: 41 words
Good Karma: 106 (vote)
Bad Karma: 120 (vote)
Next entry:  解决对象无法访问主场景函数方法举例
Previous entry:  【翻译】A situation where we shouldn't extend movieclip

Frontpage