actionscript 3: default function parameter as an empty function?
i have a function that receives a function as a parameter. examp开发者_JS百科le:
function foo(bar:Function):void() {};
how can i set a default value for the function to be an empty function so the user will not have to paste a function as a parameter ?
Functions are passed by reference, so this should work:
function foo(bar: Function = null): void {
if(!bar) {
// Replace null-ref with an empty function
bar = function(): void {}
}
// Call given function
bar();
}
精彩评论