Created
June 14, 2011 18:39
-
-
Save subtleGradient/1025545 to your computer and use it in GitHub Desktop.
Mixins as Mutators!
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
| function Events(exports){ | |
| var events = {} | |
| exports.fireEvent = function(){...} | |
| exports.addEvent = function(){...} | |
| // etc... | |
| return exports | |
| } |
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
| var foo = {} | |
| Events(foo) | |
| foo.addEvent(...) |
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
| Events(Element.prototype); | |
| Events(Request.prototype); | |
| // etc... |
Author
I'm not advocating for this pattern, just experimenting with the syntax.
Another drawback is that since they are new functions for every instance, you probably lose out on the speed boost of compiled functions that the V8 engine gives you.
Good that in javascript we can just copy functions from other object's prototype...
And even remove moo wrapping through .$origin if needed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cool, except that it creates functions on every call.
Why y no use prototype to store the methods??? it's extendable