2007年5月26日星期六

Default Values for Function Parameters

ActionSript 3 now allows you to specify default values for your function's parameters. In doing so, that parameter then becomes optional and the default value assigned to the respective argument in the function call if a value is explicitly not provided.

ActionScript Code:

function method(required:String, optional:String = "default"):void {
trace(required +" "+optional);
}
method(
"Hello"); // "Hello default"


You can only place parameters with default values after all required parameters. In other words you can't have

ActionScript Code:

// Incorrect:
function method(required:
String = "default", optional:String):void { ...


since there would be no way for optional to be set without required having to be set as well.

2 评论:

Typhone 说...

哈哈。。。這個默認值的好處就是在做demo時比較方便,其它的好處還沒看出來!

Unknown 说...

Typhone你好啊,申请友情链接,我的博客已经做好贵站的链接。请检查。http://www.lalako.com

我的博客:lalako
地址:http://www.lalako.com