I have seen, mostly in event handlers, functions called Pascal-style, i.e. without the brackets. Is there a difference between myFunction and myFunction(), and if so, what is it?
I have seen, mostly in event handlers, functions called Pascal-style, i.e. without the brackets.
Share
You always use parentheses when you want to call a function.
The reason that you use it without parentheses when you want it to be a callback function is that you don’t want to call the function when you assign it to the event. The event will call the function when the event is triggered.
You can pass a function reference around like any other value, and use parentheses when you want to call it. Example: