Skip to content

Instantly share code, notes, and snippets.

@fabrizim
Created January 2, 2012 17:32
Show Gist options
  • Save fabrizim/1551466 to your computer and use it in GitHub Desktop.
Save fabrizim/1551466 to your computer and use it in GitHub Desktop.
Example using Simple Event Mixin
/**
* A quick example of how to use Simple events on an arbitrary javascript class.
*/
var Cat = function(){
var self = this;
this.on('hairball', function(){
self.throwup();
});
};
EventMixin(Cat);
Cat.prototype.throwup = function(){
console.log("jaw dislocates, body heaves, here it comes... bwahhhhahahahhaha!");
};
Cat.prototype.lickFur = function(){
console.log("(disturbing licking sounds...)");
};
Cat.prototype.clean = function(){
var self = this;
console.log("i'm gross, time to clean take a bath.");
this.lickFur();
console.log("all clean!");
setTimeout( function(){
console.log('uh-oh...');
self.emit('hairball');
}, 1000);
};
var putty = new Cat();
putty.clean();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment