Huggy Bear
Huggy was so cool he owned an iPad in the 70s!
What it does
TL;DR; Mixins without the mess
HuggyBear helps you add behaviour to your objects (typically model instances) without compromising their public signatures.
Status
An example
Suppose an instance of the People
prototype, with 3 methods: walk
, sleep
, work
(very limited, huh?).
Now you want the instances of People
to be also instances of EventEmitter
, you'll have to add on
, off
, emit
.
And now, you want the instances of People
to do PubSub
, then you add publish
and subscribe
.
So what ?
So your handcrafted People
that originally contains 3 methods, has just lost its essence and is now
a kind of a hydra with 8 methods, namely walk
, sleep
, work
, on
, off
, emit
, publish
, register
.
HuggyBear helps keeping your models sane and simple.
Some code, please
var huggyBear = ; { huggyBear;} Peopleprototype = {} {} {} var ppl = ;// The following will throw a TypeError, obviouslyppl; //This is the HuggyBear way:pplEventEmitter = huggyBear;pplEventEmitter; //OK
Of course, this will work with any object
You don't have to put it in the constructor, of course. You're free to add functionnality whenever you need to.
Tips on using huggyBear
HuggyBear everywhere
You may want to bring HuggyBear
to every object...
var huggyBear = ; Objectprototype { return huggyBearprovide;} Objectprototype { return huggyBearclaim;}
License
MIT