0

I came over a piece of code in a custom component that I have some trouble understanding.

public onTouch: () => void = () => {}

The onTouch function is set by the private method

registerOnTouch(fn: any) {
  this.onTouch = fn;
}

I think that the first part public OnTouch: () = void declares a function without parameters that does not return a value. But I struggle to understand the last part () => ().

What does the latter part describe Could it be an overload?

1 Answer 1

2

The first part:

() => void

declares the type of function onTouch and the second part:

= () => {}

declares its default value. That is, in case onTouch is not assigned another value, it will be a no-op.

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.