Hey Samuel,

I'd be happy to discuss the inheritance chain problems with you and to
see if this library helps.

I've whipped up a sample of creating a new mixin from scratch:
https://github.com/kmalakoff/examples-kmalakoff

    # define a new mixin for a superstar with fans
    Mixin.registerMixin({
      mixin_name: 'Superstar'

      initialize: ->
        # create instance data with an array of fans
        Mixin.instanceData(this, 'Superstar', {fans: []})

      mixin_object: {
        addFan: (fan) ->
          # get the instance data, and add the fan to the fans array
          Mixin.instanceData(this, 'Superstar').fans.push(fan)
          return this # allow chaining

        getFans: ->
          return Mixin.instanceData(this, 'Superstar').fans
      }
    })

    class Rockstar
    rockstar1 = new Rockstar()
    Mixin.in(rockstar1, 'Superstar')

    class Fan
    fan1 = new Fan(); fan2 = new Fan()
    rockstar1.addFan(fan1).addFan(fan2)

    ####################################################
    # Validating the example
    ####################################################
    fans = rockstar1.getFans()
    equal(fans[0], fan1, 'fan1 is a fan of rockstar1')
    equal(fans[1], fan2, 'fan2 is a fan of rockstar1')

    # cleanup
    Mixin.out(rockstar1)

Just let me know if you'd like to discuss or if you look at the code
and have some feedback to make it better.

Cheers,

Kevin


On Oct 10, 3:29 pm, Samuel Richardson <s...@richardson.co.nz> wrote:
> Hey Kevin,
>
> Can't speak for the code quality but I really like the concept. I was trying
> to implement mixins for a recent project that used coffeescripts
> class/extends functionality but was running into problems with
> the inheritance chain. This sounds like it would be nicely suited for what I
> wanted to do.
>
> Samuel Richardsonwww.richardson.co.nz| 0405 472 748
>
>
>
>
>
>
>
> On Mon, Oct 10, 2011 at 3:56 PM, kmalakoff <xmann.i...@gmail.com> wrote:
> > Hi everyone,
>
> > In a personal project, I started using Javascript mixins quite heavily
> > and recently refactored out the code into a library:
> >https://github.com/kmalakoff/mixin
>
> > I've been using and improving this over the last 3 months and I'm
> > really excited about sharing it with the JS community, but I'm not
> > sure what people think especially since playing around with prototypes
> > can be frowned upon.
>
> > The only feedback I have received so far is that is might be hard to
> > debug and seemed a bit complex. For debugging, I implemented a
> > statistics module to be able to look at memory usage and would argue
> > that the complexity matches the problem, but I'd like to get some more
> > feedback! (thank you Angus for suggesting jsmentors)
>
> > Here are three blog posts with examples so you know what I'm trying to
> > achieve:
>
> > 1)
> >http://braincode.tumblr.com/post/11026285083/mixin-js-the-javascript-...
> > 2)
> >http://braincode.tumblr.com/post/11100271168/mixin-js-view-with-model...
> > 3)
> >http://braincode.tumblr.com/post/11265571365/mixin-js-subscriptions-e...
>
> > The above GitHub repository has tests both for the library and for the
> > initial 7 mixins I released (RefCount, Flags, AutoMemory,
> > Subscriptions, Timeouts and 2 or Backbone.js) and the working examples
> > from the blog posts can be found here:
> >https://github.com/kmalakoff/examples-kmalakoff
>
> > Any feedback would be much appreciated.
>
> > Cheers,
>
> > Kevin
>
> > --
> > To view archived discussions from the original JSMentors Mailman list:
> > http://www.mail-archive.com/jsment...@jsmentors.com/
>
> > To search via a non-Google archive, visit here:
> >http://www.mail-archive.com/jsmentors@googlegroups.com/
>
> > To unsubscribe from this group, send email to
> > jsmentors+unsubscr...@googlegroups.com

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/jsmentors@jsmentors.com/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/jsmentors@googlegroups.com/

To unsubscribe from this group, send email to
jsmentors+unsubscr...@googlegroups.com

Reply via email to