0

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 ?

1 Answer 1

6

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();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.