Created
May 2, 2012 12:02
-
-
Save kimjoar/2576108 to your computer and use it in GitHub Desktop.
EventEmitter example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var events = new EventEmitter(); | |
| var UserView = function(el, user) { | |
| this.el = el; | |
| this.user = user; | |
| // Let's listen for someone emitting the event 'user:showImage', which | |
| // we listen for and then show the user's image. | |
| // The first parameter is the event name, the second is the function | |
| // to call when the event is triggered, and the third is the context | |
| // the function is called with. | |
| events.addListener('user:showImage', this.showImage, this); | |
| // We can also emit events. Let's tell listeners that we have created | |
| // a user view. | |
| events.emit('user:created'); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment