Created
January 2, 2012 17:32
-
-
Save fabrizim/1551466 to your computer and use it in GitHub Desktop.
Example using Simple Event Mixin
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
/** | |
* 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