

JavaScript Mixins for grown-ups - northstar
http://javascriptweblog.wordpress.com/2011/05/31/a-fresh-look-at-javascript-mixins/#

======
extension
Note that the way mixins generally work in languages with first class support
for them is with multiple inheritance.  That is, mixins are included by
reference and, in a dynamic language, changes to the mixin affect objects that
have already been extended. 

JavaScript can't do multiple inheritance and so you have to hack mixins by
copying.  This sucks when you want to e.g. extend an Enumerable mixin because..
well, you can't. 

~~~
pas
> JavaScript can't do multiple inheritance

JS's object modell is prototype based, so there's no traditional inheritance,
just the chain of prototypes.  And you can monkey patch it any way you like at
any level. ( Adding currying to Function.prototype is a nice and scary example
of this.) 

Directly defining functions into the prototype chain doesn't even require
copying and you can put an arbitrary number of functions there.  And you can
just redefine the Enumerable mixin's functions, or wrap then into your
functions, so extending isn't a problem. 

~~~
extension
By "multiple inheritance", I mean children can inherit features from multiple
parents, whatever the constraints on those parents may be.  Ruby, for example,
uses modules for this purpose. 

Because JS objects can only have a single prototype, you can't inherit from
multiple places orthogonally.  If you insert mixins into the prototype chain
then they can't be shared between multiple chains, and so aren't really
mixins. 

------
nxn
This post inspired me to try and create the mixin pattern in C# with
interfaces, extension methods, and optional generics.  Probably been done
before, but meh, here's the result: <http://pastebin.com/ZiddNDSi>

