Skip to content

Instantly share code, notes, and snippets.

@kimjoar
Created May 2, 2012 12:02
Show Gist options
  • Select an option

  • Save kimjoar/2576108 to your computer and use it in GitHub Desktop.

Select an option

Save kimjoar/2576108 to your computer and use it in GitHub Desktop.
EventEmitter example
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