Created
May 28, 2012 12:06
-
-
Save klovadis/2818810 to your computer and use it in GitHub Desktop.
Example of "this" within event listeners
This file contains 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
// 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