Skip to content

Instantly share code, notes, and snippets.

@wkf
Created February 14, 2014 15:31
Show Gist options
  • Save wkf/9003032 to your computer and use it in GitHub Desktop.
Save wkf/9003032 to your computer and use it in GitHub Desktop.
_ = require('lodash')
_.mixin({
acts: function(object, mixin) {
_.extend(object.prototype, mixin.prototype);
}
});
function Thing() {}
Thing.prototype.hello = function () {
return 'hello world';
}
function Behavior() {}
Behavior.prototype.action = function () {
return 'does action';
}
_(Thing).acts(Behavior)
// ...or a special method could be avoided entirely
// _(Thing.prototype).extend(Behavior.prototype)
t = new Thing
console.log(t.hello())
console.log(t.action())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment