Created
June 22, 2012 00:27
-
-
Save hughfdjackson/2969479 to your computer and use it in GitHub Desktop.
LucidJS example
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
| /* | |
| LucidJS is a lib with a .emitter constructor function (one that doesn't require the new keyword; what i | |
| tend to call informal constructor functions). It provides an object with the normal pub/sub methods; .on, | |
| .off and .trigger | |
| */ | |
| var player = _.extend({ | |
| x: 0 | |
| , y: 0 | |
| , move: function(x, y){ | |
| this.x += x | |
| this.y += y | |
| this.trigger('change', 'has moved') | |
| } | |
| , LucidJS.emitter()) | |
| player.on('change', function(msg){ console.log(msg) }) | |
| player.move(1, 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment