开发者

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();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜