Skip to content

Instantly share code, notes, and snippets.

@klovadis
Created May 28, 2012 12:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klovadis/2818810 to your computer and use it in GitHub Desktop.
Save klovadis/2818810 to your computer and use it in GitHub Desktop.
Example of "this" within event listeners
// create EventEmitter instance
var myEventEmitter = new EventEmitter();
// attach a property
myEventEmitter.someVar = "some var";
// add event listener for "test"
myEventEmitter.on('test', function ()
console.log(this.someVar);
});
// will output "some var"
myEventEmitter.emit('test');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment