On demand, persistent and unobstrusive dependencies

Huggy Bear

Huggy was so cool he owned an iPad in the 70s!

TL;DR; Mixins without the mess

HuggyBear helps you add behaviour to your objects (typically model instances) without compromising their public signatures.

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 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.

var huggyBear = require('huggybear')();
function People () {
  huggyBear.provide(this, 'EventEmitter', new EventEmitter());
People.prototype = {
  walkfunction () {},
  sleepfunction () {},
  workfunction () {}
var ppl = new People();
// The following will throw a TypeError, obviously 
ppl.on('eventName', function () {});
//This is the HuggyBear way: 
pplEventEmitter = huggyBear.claim(ppl, 'EventEmitter');
pplEventEmitter.on('eventName', function () {}); //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

You may want to bring HuggyBear to every object...

var huggyBear = require('huggybear')();
Object.prototype.provide = function (namedefinition) {
  return huggyBear.provide.apply(undefined, [this].concat(;
Object.prototype.claim = function (/*name*/) {
  return huggyBear.claim.apply(undefined, [this].concat(;