Skip to content

Instantly share code, notes, and snippets.

@subtleGradient
Created June 14, 2011 18:39
Show Gist options
  • Select an option

  • Save subtleGradient/1025545 to your computer and use it in GitHub Desktop.

Select an option

Save subtleGradient/1025545 to your computer and use it in GitHub Desktop.
Mixins as Mutators!
function Events(exports){
var events = {}
exports.fireEvent = function(){...}
exports.addEvent = function(){...}
// etc...
return exports
}
var foo = {}
Events(foo)
foo.addEvent(...)
Events(Element.prototype);
Events(Request.prototype);
// etc...
@Inviz

Inviz commented Jun 15, 2011

Copy link
Copy Markdown

Cool, except that it creates functions on every call.

Why y no use prototype to store the methods??? it's extendable

@subtleGradient

Copy link
Copy Markdown
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.

@Inviz

Inviz commented Jun 15, 2011

Copy link
Copy Markdown

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