dilvie/stampit — pull request #9 by bitmage (2013-07-30 04:12:11+00:00)
Title: compose preserves inheritance chain on first argument

Hey, I found that while my first example with the EventEmitter worked, another example with a Writable Stream did not. Digging into this, I discovered that the 'compose' method was doing a shallow merge, and so was not maintaining the inheritance chain.

Multiple inheritance seems like a harder problem to solve, but I was able to support single inheritance on the first arg by calling 'create' in that case. This seems like a really useful pattern, as I can start with my EventEmitter/Stream/Whatever and extend from it with whatever mixins I would like.

Is it possible/desirable to do multiple inheritance composition? It might look something like this:

a1 -> a2 -> a3
b1 -> b2 -> b3

stampit.compose a1, b1

b1 -> b2 -> b3 -> a1 -> a2 -> a3

I.E. The rightmost arg becomes the base. The problem with this is you only have a1 and b1 as references, and I don't know if there's any way to walk your way up the prototype chain to modify b3 to point to a1.

Anyway, that's probably an issue for another day, if ever. I think the current change will be helpful. Make sure you test it, as I only performed limited testing within my sample code.