Why use event listeners over function calls?
Posted
by
Organiccat
on Stack Overflow
See other posts from Stack Overflow
or by Organiccat
Published on 2010-12-21T20:43:36Z
Indexed on
2010/12/21
20:54 UTC
Read the original article
Hit count: 267
I've been studying event listeners lately and I think I've finally gotten them down. Basically, they are functions that are called on another object's method. My question is, why create an event listener when calling the function will work just fine?
Example, I want to call player.display_health(), and when this is fired, the method player.get_health() should be fired and stored so that display_health() has access to it. Why should I use an event listener over simply calling the function? Even if display_health() were in another object, this still doesn't appear to be a problem to me.
If you have another example that fits the usage better, please let me know. Perhaps particular languages don't benefit from it as much? (Javascript, PHP, ASP?)
© Stack Overflow or respective owner