有没有什么方法可以引用var或const作为actionscript 3中函数参数的默认值.
我可以定义默认值,如null,string,int.
function a( b = null ) { blah... }
但我想做的是
function a( b = function(){} ) { blah... }
这似乎有办法.大概通过const
奇怪的是,似乎你不能这样做,至少我无法使它工作,它不会接受任何对静态函数的引用作为默认值.
我能做的最好的就是:
public function myFunction(functionArgument:Function = null):void {
if (functionArgument != null) {
functionArgument();
} else {
defaultFunction();
}
}
Run Code Online (Sandbox Code Playgroud)
作为旁注我刚刚发现你实际上可以声明这样的函数:
public static const STATICFUNC:Function = function():void { trace("i'm static!") };
Run Code Online (Sandbox Code Playgroud)
但这似乎与宣布它们理智的方式相同,所以也没有运气.
归档时间: |
|
查看次数: |
12744 次 |
最近记录: |