Download

Difference between "send event" and "call function"?

If A wants B to do something, one way is to send event, another is call function. What should we usually do? What’s the difference between them?
One benefit I see in sending event is that if things happen in B, the logic of A won’t be jammed. But is there anything else?

  • Events cannot return values in a straightforward way
  • Events will silently do nothing if the target function (handler) is removed
  • Events can trigger multiple handlers

In short, functions are simpler and less likely to break silently as your project is changed over time, but they are less powerful. On a small project you may not suffer any consequences using the more powerful option by default, but on a large project the costs (maintenance and runtime) of the more flexible option could bite you.