views:

50

answers:

1

Hi.

i have a function that receives a function as a parameter. example:

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 ?

+5  A: 

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