Created
February 14, 2014 15:31
-
-
Save wkf/9003032 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_ = 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